## The Great Fire of Köres

View as PDF

Points: 20 (partial)
Time limit: 1.2s
Memory limit: 256M

Authors:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

The Great Forest of Köres has been set ablaze, leading to one of the greatest forest fires in all of recorded history. The country of Werłantž, which presides over the forest had luckily foreseen the event and built bunkers, where the residents of the Great Forest of Köres may escape to. There are communities of similar size living in the forest, and there are such bunkers. Since trees are blocking most of the paths in the forest, it is only possible to travel in axis-aligned directions. Each community will travel to a bunker such that they have to travel the minimal distance possible. As each bunker is large enough to hold all communities, any number of communities can travel to the same bunker. The country of Werłantž asks you to determine the total distance travelled by all communities.

#### Constraints

The coordinates of all of the locations are less than or equal to in absolute value.

##### Subtask 2 [20%]

The coordinates of all locations are less than or equal to in absolute value.

#### Input Specification

The first line contains the integer .
lines follow, the th of which contains two integers, the and coordinates of the th community.
The next line contains the integer .
lines follow, the th of which contains two integers, the and coordinates of the th bunker.

#### Output Specification

Output one integer, the sum of the distances traveled by all of the communities.

#### Sample Input

3
1 1
2 2
3 1
2
0 0
4 0

#### Sample Output

8