Fenced In

Remove fence segments between adjacent field regions so every region connects with the smallest possible total removed length.

Medium7Minimum spanning treeGreedySortingNo attempts yetTime limit2sMemory limit512 MB

Problem

Farmer John has noticed that many of his cows are agoraphobic, meaning they are afraid of large open spaces. To make grazing less frightening, he splits his large field into smaller regions by building vertical (north to south) and horizontal (east to west) fences.

The large field is a rectangle whose opposite corners are (0,0)(0,0) and (A,B)(A,B). John builds nn vertical fences at distinct positions a1,,ana_1, \ldots, a_n (0<ai<A0 < a_i < A); the fence at aia_i runs from (ai,0)(a_i, 0) to (ai,B)(a_i, B). He also builds mm horizontal fences at distinct positions b1,,bmb_1, \ldots, b_m (0<bi<B0 < b_i < B); the fence at bib_i runs from (0,bi)(0, b_i) to (A,bi)(A, b_i). Every vertical fence crosses every horizontal fence, so the field is cut into (n+1)(m+1)(n+1)(m+1) regions.

John forgot to put gates in the fences, so a cow cannot leave the region it is standing in. He wants to fix this by removing parts of some fences. He picks pairs of adjacent regions and removes the entire stretch of fence that separates them, and he wants a cow to be able to reach every part of the field through those openings.

For example, John might start from this fence pattern.

+---+--+
|   |  |
+---+--+
|   |  |
|   |  |
+---+--+

He can open it up like this.

+---+--+
|      |
+---+  +
|      |
|      |
+---+--+

Compute the minimum total length of fence John has to remove.

Input

The first line contains AA, BB, nn, and mm (1A,B1091 \le A, B \le 10^9, 0n250000 \le n \le 25000, 0m250000 \le m \le 25000). The next nn lines contain a1,,ana_1, \ldots, a_n, one per line. The mm lines after that contain b1,,bmb_1, \ldots, b_m, one per line. The aia_i are distinct and the bib_i are distinct.

Output

Print the minimum total length of fence that must be removed. The answer can exceed the range of a 32-bit integer.