Problem7837--USACO 2014 December Contest, Bronze —— Problem 1. Marathon

7837: USACO 2014 December Contest, Bronze —— Problem 1. Marathon

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 256 MiB

Description

Unhappy with the poor health of his cows, Farmer John enrolls them in an assortment of different physical fitness activities. His prize cow Bessie is enrolled in a running class, where she is eventually expected to run a marathon through the downtown area of the city near Farmer John's farm! 
The marathon course consists of $N\  (3 \leq N \leq 100,000)$ checkpoints to be visited in sequence, where checkpoint 1 is the starting location and checkpoint N is the finish. Bessie is supposed to visit all of these checkpoints one by one, but being the lazy cow she is, she decides that she will skip up to one checkpoint in order to shorten her total journey. She cannot skip checkpoints 1 or N, however, since that would be too noticeable. 
Please help Bessie find the minimum distance that she has to run if she can skip up to one checkpoint. Note that since the course is set in a downtown area with a grid of streets, the distance between two checkpoints at locations (x1, y1) and (x2, y2) is given by |x1-x2| + |y1-y2|. This way of measuring distance -- by the difference in x plus the difference in y -- is sometimes known as "Manhattan" distance because it reflects the fact that in a downtown grid, you can travel parallel to the x or y axes, but you cannot travel along a direct line "as the crow flies".

Input

The first line gives the value of N. 
The next N lines each contain two space-separated integers, x and y, representing a checkpoint $(-1000 \leq x \leq 1000,\ -1000 \leq y \leq 1000)$. The checkpoints are given in the order that they must be visited. Note that the course might cross over itself several times, with several checkpoints occurring at the same physical location. When Bessie skips such a checkpoint, she only skips one instance of the checkpoint -- she does not skip every checkpoint occurring at the same location.

Output

Output the minimum distance that Bessie can run by skipping up to one checkpoint.

Sample 1 Input

4
0 0
8 3
11 -1
10 0

Sample 1 Output

14

HINT

相同题目:USACO Bronze

Source/Category