This page is still under construction.

Parts of this page are still being built. What you see may change.

Academic Distance

Interview

Time limit2sMemory limit512 MB

Summary
Given N points in order, compute the total Manhattan distance along the path from the first point to the last.
Level

Easy1 of 10

Topics
Implementation, Math, Array
Solved
No attempts yet

Problem

Starting from the second semester, Mr. Eto will take classes at Kyoto University. He is not accustomed to the structure of the university because in the first semester he had only online lectures.

There are NN classes today. The schedule contains the coordinates of NN classrooms in the order in which they have to be visited. The coordinates of the ii-th classroom are (xi,yi)(x_i, y_i). Assuming Mr. Eto starts the day in the first classroom and ends in the NN-th classroom, calculate the total distance he has to travel.

On the Kyoto University campus, the distance traveled from the coordinates (a,b)(a, b) to the coordinates (c,d)(c, d) is ∣a−c∣+∣b−d∣|a-c| + |b-d|.

Input

The first line of the input contains one integer NN (1≤N≤1001 \le N \le 100), the number of classrooms in today's schedule. Then NN lines follow, the ii-th of them containing the integer coordinates xix_i and yiy_i of the ii-th classroom in the schedule (−100≤xi,yi≤100-100 \le x_i, y_i \le 100).

Output

Print one integer: the total distance traveled by Mr. Eto by the end of the day.

Examples3

  1. Example 1

    Input
    3
    1 2
    2 3
    4 6
    
    Expected output
    7
    
  2. Example 2

    Input
    1
    0 0
    
    Expected output
    0
    
  3. Example 3

    Input
    4
    -2 3
    1 4
    5 2
    4 -2
    
    Expected output
    15