Marathon 1
InterviewTime limit1sMemory limit256 MB
Run checkpoints 1 to N in order while skipping exactly one middle checkpoint to minimize the total Manhattan distance.
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 checkpoints. The marathon ends once a cow starts at checkpoint 1, visits every checkpoint in order of its number, and finishes at checkpoint . 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 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 and is , where denotes absolute value.
Input
The first line contains the number of checkpoints . ()
Each of the next lines contains two integers. The first integer on line is the coordinate of checkpoint , and the second is its coordinate. ()
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 , whose length is 14. He cannot run any shorter than that.