Cow Checklist
Every day, Farmer John walks through his pasture to check on the well-being of each of his cows. On his farm he has two breeds of cows, Holsteins and Guernseys. His h Holsteins are conveniently numbered 1 .. h, and his g Guernseys are conveniently numbered 1 .. g. Each cow is located at a point in the 2D plane (not necessarily distinct).
Farmer John starts his tour at Holstein 1, and ends at Holstein H. He wants to visit each cow along the way, and for convenience in maintaining his checklist of cows visited so far, he wants to visit the Holsteins and Guernseys in the order in which they are numbered. In the sequence of all h + g cows he visits, the Holsteins numbered 1 .. h should appear as a (not necessarily contiguous) subsequence, and likewise for the Guernseys. Otherwise stated, the sequence of all h + g cows should be formed by interleaving the list of Holsteins numbered 1 .. h with the list of Guernseys numbered 1 .. g.
When FJ moves from one cow to another cow traveling a distance of d, he expends d^2
energy. Please help him determine the minimum amount of energy required to visit all his cows according to a tour as described above.
Input
The first line contains h and g (1 ≤ h ≤ 1000, 1 ≤ g ≤ 1000). The next h lines contain the x and y coordinates of the h Holsteins, and the next g lines after that contain coordinates of the Guernseys. Each coordinate is an integer in the range 0 .. 1000.
Output
Write a single line of output, giving the minimum energy required for FJ's tour of all the cows.