#P3039. FJ's Farm Delivery Route
FJ's Farm Delivery Route
FJ's Farm Delivery Route
FJ has \(N\) farms with unique integer coordinates \((x_i, y_i)\) for \(1 \le i \le N\) where \(1 \le x_i, y_i \le 10^6\). He must plan a supply delivery route that starts at farm 1, visits farms 2, 3, \(\ldots\), \(N\) in order, and finally returns to farm 1.
FJ can only move in the four cardinal directions (north, south, east, west). Each unit move takes 1 minute. Note that aside from farm 1 which is visited twice (at the start and the end), every other farm is visited exactly once.
The time cost is therefore the sum of the Manhattan distances between consecutive farms in the route. That is, if the coordinates of the farms are \((x_1, y_1), (x_2, y_2), \ldots, (x_N, y_N)\), the total time is given by:
\[ T = \sum_{i=1}^{N-1} \left(|x_{i+1} - x_i| + |y_{i+1} - y_i|\right) + \left(|x_{1} - x_N| + |y_{1} - y_N|\right). \]inputFormat
The first line contains an integer \(N\) (\(1 \le N \le 100\)), representing the number of farms.
The following \(N\) lines each contain two space-separated integers \(x_i\) and \(y_i\) (\(1 \le x_i, y_i \le 10^6\)), representing the coordinates of the \(i\)-th farm.
outputFormat
Output a single integer, which is the minimum time (in minutes) required for the delivery route.
sample
4
1 1
2 2
3 3
4 4
12