#P2848. Holstein's Tour

    ID: 16106 Type: Default 1000ms 256MiB

Holstein's Tour

Holstein's Tour

Farmer John has two breeds of cows on his farm: Holsteins and Guernseys. The Holsteins are numbered from 11 to HH, and the Guernseys are numbered from 11 to GG. Each cow is located at a point in the 2D plane. Farmer John begins his tour at Holstein 11 and must finish at Holstein HH. He needs to visit every cow, but for convenience he wishes to visit the cows in the order of their numbering within each breed. In other words, in the overall tour of H+GH+G cows, the sequence of Holsteins 1,2,,H1,2,\ldots,H and the sequence of Guernseys 1,2,,G1,2,\ldots,G must each appear as a (not necessarily contiguous) subsequence.

When moving from one cow at point (x1,y1)(x_1, y_1) to the next cow at point (x2,y2)(x_2, y_2), Farmer John expends energy equal to the square of the Euclidean distance, i.e.,

(x2x1)2+(y2y1)2.(x_2-x_1)^2 + (y_2-y_1)^2.

Your task is to determine the minimum total energy required for Farmer John to complete his tour under these conditions.

inputFormat

The first line of input contains two integers HH and GG (1H10001 \leq H \leq 1000, 1G10001 \leq G \leq 1000), representing the number of Holsteins and Guernseys respectively. The next HH lines each contain two integers, representing the xx and yy coordinates of the Holstein cows in order. The following GG lines each contain two integers, representing the xx and yy coordinates of the Guernsey cows in order.

outputFormat

Output a single integer which is the minimum total energy that Farmer John expends in his tour.

sample

2 1
0 0
1 0
0 1
3

</p>