{"problem":{"name":"ReTravel","description":{"content":"On the $xy$\\-plane, there are $N$ points labeled $1, 2, \\dots, N$. The coordinates of point $i$ ($1 \\le i \\le N$) are $(X_i, Y_i)$. There is a robot at the origin of this plane. Your task is to contro","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"ttpc2024_1_e"},"statements":[{"statement_type":"Markdown","content":"On the $xy$\\-plane, there are $N$ points labeled $1, 2, \\dots, N$. The coordinates of point $i$ ($1 \\le i \\le N$) are $(X_i, Y_i)$.\nThere is a robot at the origin of this plane. Your task is to control the robot to visit all the points $1, 2, \\dots, N$ **in this order**.\nThe robot has a string variable $S$, which is initially an empty string.  \nYou can move the robot using the following four types of operations:\n\n*   Operation $1$: Increase the robot's $x$ coordinate by $1$ and append `X` to the end of $S$. This operation costs $1$.\n*   Operation $2$: Increase the robot's $y$ coordinate by $1$ and append `Y` to the end of $S$. This operation costs $1$.\n*   Operation $3$: Decrease the robot's $x$ coordinate by $1$ and remove the last character of $S$. This operation can only be performed if the last character of $S$ is `X`. This operation costs $0$.\n*   Operation $4$: Decrease the robot's $y$ coordinate by $1$ and remove the last character of $S$. This operation can only be performed if the last character of $S$ is `Y`. This operation costs $0$.\n\nFind the minimum cost required for the robot to visit all points $1, 2, \\dots, N$ in this order.\n\n## Constraints\n\n*   All input values are integers.\n*   $1 \\le N \\le 500$\n*   $0 \\le X_i, Y_i \\le 10^9$\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$\n$X_1$ $Y_1$\n$X_2$ $Y_2$\n$\\vdots$\n$X_N$ $Y_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"ttpc2024_1_e","tags":[],"sample_group":[["2\n3 3\n1 2","6\n\nBy performing Operation $1$ once, Operation $2$ three times, and Operation $1$ twice, you can reach point $1$.  \nThen, by performing Operation $3$ twice and Operation $4$ once, you can reach point $2$.\nThe total cost of this sequence of operations is the sum of the number of times Operations $1$ and $2$ are performed, which is $6$."],["3\n2 2\n3 3\n1 3","7"]],"created_at":"2026-03-03 11:01:14"}}