cho.sh
Notes
Loading...

Cake Delivery

Time limit

2s

Memory limit

128 MB

Problem

Sunah works at a cake delivery shop and wants to deliver the cakes she made herself. There are N customers, and she must deliver to them only in the order in which the orders were placed.

The shop location and the N customer locations are given as integer coordinates on a 100,000 by 100,000 grid. Sunah can move one grid cell at a time in the four cardinal directions. To deliver to a customer, she must reach either that customer's grid point or one of the four grid points directly adjacent to it.

Find the minimum distance Sunah must move to finish all deliveries while preserving the input order of the customers. Distance means the number of grid cells moved. Even if she is at a position where she could deliver to a later customer, she cannot deliver to that customer before their turn. Multiple customers may be located at the same position.

Input

The first line contains the number of customers N. The second line contains the shop location as X Y. Each of the next N lines contains a customer's location as X Y in delivery order. There is at least one space between the two coordinates.

(1 <= N, X, Y <= 100,000)

Output

Print the minimum distance needed to complete all deliveries in order.