Cow Checklist#10563

Cow Checklist

1 second
128 megabytes
Medium

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 Holsteins are conveniently numbered , and his Guernseys are conveniently numbered . Each cow is located at a point in the 2D plane (not necessarily at a distinct point).

Farmer John starts his tour at Holstein and ends at Holstein . He wants to visit every cow along the way. For convenience in maintaining his checklist of cows visited so far, he wants to visit the Holsteins and Guernseys in numerical order. In the sequence of all h + g cows he visits, the Holsteins numbered must appear as a (not necessarily contiguous) subsequence, and likewise for the Guernseys. In other words, the sequence of all h + g cows must be formed by interleaving the list of Holsteins numbered with the list of Guernseys numbered .

When FJ moves from one cow to another over a distance of , he expends d^2 units of energy. Please help him determine the minimum amount of energy required to visit all his cows according to the rules described above.

Input

The first line contains and g~(1 \le h \le 1000, 1 \le g \le 1000). The next lines contain the and coordinates of the Holsteins, followed by the next lines containing the coordinates of the Guernseys. Each coordinate is an integer in the range .. .

Output

Print the minimum amount of energy required for FJ's tour of all the cows.

Examples

Example 1

Loading
Loading