Hermes
In a modern city inhabited by Greek gods, the streets form an integer grid, running parallel to the x and y axes. For every integer Z, there is a horizontal street at y=Z and a vertical street at x=Z. Each intersection of these streets occurs at integer coordinates, and each pair of integers corresponds to a specific intersection. On hot days, the gods relax in cafeterias located at these intersections. Hermes, the messenger, must deliver light messages to the gods in the cafeterias, traveling only along the city's streets. Each message is meant for a specific god, but it doesn't matter if other gods see it.
The messages must be delivered in a precise order, so Hermes receives the coordinates of the cafeterias in this sequence. He begins his journey at the point (0, 0). To deliver a message to a cafeteria at coordinates (X_i, Y_i), Hermes only needs to reach a point on the same horizontal street (with y-coordinate Y_i) or the same vertical street (with x-coordinate X_i). Once all messages are delivered, Hermes stops.
Your task is to write a program that, given the sequence of cafeteria coordinates, calculates the minimum total distance Hermes must travel to deliver all the messages.
Input
The first line of the input contains a single integer N – the number of messages to be delivered. The following N lines provide the coordinates of the N street intersections where the messages need to be sent, in the specified order. Each of these N lines contains two integers: the first is the x-coordinate and the second is the y-coordinate of the intersection.
For all test cases, 1 ≤ N ≤ 20000, and -1000 ≤ X_i, Y_i ≤ 1000. In 50% of the test cases: 1 ≤ N ≤ 80.
Output
The output should consist of a single line containing one integer – the minimum total distance Hermes needs to travel to deliver all the messages.