Under construction

Still being built. Things may change

Marathon 1

Interview

Time limit1sMemory limit256 MB

Summary
Run checkpoints 1 to N in order while skipping exactly one middle checkpoint to minimize the total Manhattan distance.
Level

Easy3 of 10

Topics
Greedy, Array, Math
Solved
No attempts yet

Problem

Farmer John decided that the cows on his farm are out of shape, so he organized a marathon for them. Seungwon, his favorite cow, is entering the race.

The course has NN checkpoints. The marathon ends once a cow starts at checkpoint 1, visits every checkpoint in order of its number, and finishes at checkpoint NN. Seungwon is lazy, and now that the race is about to start he cannot be bothered, so he plans to secretly skip one of the checkpoints in the middle. Skipping checkpoint 1 or checkpoint NN would be too obvious, so he will not skip either of those two.

If Seungwon may skip one checkpoint while he runs, what is the shortest distance he has to run?

The cow marathon takes place in the middle of downtown Seoul, so distance is measured as taxicab distance (Manhattan distance). The distance between (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) is ∣x1−x2∣+∣y1−y2∣|x_1 - x_2| + |y_1 - y_2|, where ∣x∣|x| denotes absolute value.

Input

The first line contains the number of checkpoints NN. (3≤N≤1000003 \le N \le 100000)

Each of the next NN lines contains two integers. The first integer on line ii is the xx coordinate of checkpoint ii, and the second is its yy coordinate. (−1000≤x,y≤1000-1000 \le x, y \le 1000)

Two different checkpoints may share the same coordinates. When Seungwon skips a checkpoint he skips only that one number, and he still visits every other checkpoint that sits on the same point.

Output

Print the shortest distance Seungwon has to run when he skips exactly one checkpoint.

Hint

In the first sample Seungwon may skip checkpoint 2 or checkpoint 3. Skipping checkpoint 2 gives the route (0,0)→(11,−1)→(10,0)(0, 0) \to (11, -1) \to (10, 0), whose length is 14. He cannot run any shorter than that.

Examples3

  1. Example 1

    Input
    4
    0 0
    8 3
    11 -1
    10 0
    
    Expected output
    14
    
  2. Example 2

    Input
    3
    0 0
    5 5
    0 0
    
    Expected output
    0
    
  3. Example 3

    Input
    5
    0 0
    1 0
    2 0
    3 0
    4 0
    
    Expected output
    4