{"raw_statement":[{"iden":"problem statement","content":"Takahashi is at the origin of a number line. Takahashi wants to reach the goal at coordinate $X$.\nAlso, there are $N$ walls and $N$ hammers on the number line.\n\n*   At coordinates $Y_1,Y_2,\\dots,Y_N$ are walls of types $1,2,\\dots,N$, respectively.\n    *   Initially, Takahashi cannot get over the walls.\n*   At coordinates $Z_1,Z_2,\\dots,Z_N$ are hammers of types $1,2,\\dots,N$, respectively.\n    *   When he arrives at a coordinate with a hammer, he obtains the hammer.\n    *   The hammer of type $i$ is dedicated to destroying the wall of type $i$. After he obtains the hammer of type $i$, he can destroy the wall of type $i$ and get over it.\n\nDetermine if he can reach the goal. If he can, find the minimum distance he travels."},{"iden":"constraints","content":"*   All values in the input are integers.\n*   $1 \\le N \\le 1500$\n*   $1 \\le |X|,|Y_i|,|Z_i| \\le 10^9$\n*   The $(2 \\times N + 1)$ coordinates $X,Y_i$ and $Z_i$ are distinct."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$ $X$\n$Y_1$ $Y_2$ $\\dots$ $Y_N$\n$Z_1$ $Z_2$ $\\dots$ $Z_N$"},{"iden":"sample input 1","content":"3 10\n-2 8 -5\n5 -10 3"},{"iden":"sample output 1","content":"40\n\nTakahashi can reach the goal by traveling a distance of $40$ as follows, which is the minimum possible:\n\n*   He starts at coordinate $0$.\n*   He moves to coordinate $3$ to obtain the hammer of type $3$.\n*   He moves to coordinate $5$ to obtain the hammer of type $1$.\n*   He moves to coordinate $-2$ to destroy the wall of type $1$.\n*   He moves to coordinate $-5$ to destroy the wall of type $3$.\n*   He moves to coordinate $-10$ to obtain the hammer of type $2$.\n*   He moves to coordinate $8$ to destroy the wall of type $2$.\n*   He moves to coordinate $10$, which is the goal."},{"iden":"sample input 2","content":"5 -1\n10 -20 30 -40 50\n-10 20 -30 40 -50"},{"iden":"sample output 2","content":"1\n\nIt may not be required that he obtains a hammer or destroys a wall to reach the goal."},{"iden":"sample input 3","content":"1 100\n30\n60"},{"iden":"sample output 3","content":"\\-1\n\nTakahashi cannot obtain the hammer of type $1$, and neither can he reach the goal."},{"iden":"sample input 4","content":"4 865942261\n703164879 -531670946 -874856231 -700164975\n-941120316 599462305 -649785130 665402307"},{"iden":"sample output 4","content":"4078987507"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}