{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n section pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"Problem Statement","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eAlong a road running in an east-west direction, there are \u003cvar\u003e\\(A\\)\u003c/var\u003e shrines and \u003cvar\u003e\\(B\\)\u003c/var\u003e temples.\r\nThe \u003cvar\u003e\\(i\\)\u003c/var\u003e-th shrine from the west is located at a distance of \u003cvar\u003e\\(s_i\\)\u003c/var\u003e meters from the west end of the road, and the \u003cvar\u003e\\(i\\)\u003c/var\u003e-th temple from the west is located at a distance of \u003cvar\u003e\\(t_i\\)\u003c/var\u003e meters from the west end of the road.\u003c/p\u003e\r\n\u003cp\u003eAnswer the following \u003cvar\u003e\\(Q\\)\u003c/var\u003e queries:\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003eQuery \u003cvar\u003e\\(i\\)\u003c/var\u003e (\u003cvar\u003e\\(1 \\leq i \\leq Q\\)\u003c/var\u003e): If we start from a point at a distance of \u003cvar\u003e\\(x_i\\)\u003c/var\u003e meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Constraints","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cul\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq A, B \\leq 10^5\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq Q \\leq 10^5\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq s_1 \u0026lt; s_2 \u0026lt; ... \u0026lt; s_A \\leq 10^{10}\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq t_1 \u0026lt; t_2 \u0026lt; ... \u0026lt; t_B \\leq 10^{10}\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq x_i \\leq 10^{10}\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(s_1, ..., s_A, t_1, ..., t_B, x_1, ..., x_Q\\)\u003c/var\u003e are all different.\u003c/li\u003e\r\n\u003cli\u003eAll values in input are integers.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Input","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eInput is given from Standard Input in the following format:\u003c/p\u003e\r\n\u003cpre\u003e\u003cvar\u003e\\(A\\)\u003c/var\u003e \u003cvar\u003e\\(B\\)\u003c/var\u003e \u003cvar\u003e\\(Q\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(s_1\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(:\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(s_A\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(t_1\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(:\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(t_B\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(x_1\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(:\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(x_Q\\)\u003c/var\u003e\r\n\u003c/pre\u003e\r\n\r\n\u003c/section\u003e\r\n"}},{"title":"Output","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003ePrint \u003cvar\u003e\\(Q\\)\u003c/var\u003e lines. The \u003cvar\u003e\\(i\\)\u003c/var\u003e-th line should contain the answer to the \u003cvar\u003e\\(i\\)\u003c/var\u003e-th query.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 1","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2 3 4\r\n100\r\n600\r\n400\r\n900\r\n1000\r\n150\r\n2000\r\n899\r\n799\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e350\r\n1400\r\n301\r\n399\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003cp\u003eThere are two shrines and three temples. The shrines are located at distances of \u003cvar\u003e\\(100, 600\\)\u003c/var\u003e meters from the west end of the road, and the temples are located at distances of \u003cvar\u003e\\(400, 900, 1000\\)\u003c/var\u003e meters from the west end of the road.\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003eQuery \u003cvar\u003e\\(1\\)\u003c/var\u003e: If we start from a point at a distance of \u003cvar\u003e\\(150\\)\u003c/var\u003e meters from the west end of the road, the optimal move is first to walk \u003cvar\u003e\\(50\\)\u003c/var\u003e meters west to visit a shrine, then to walk \u003cvar\u003e\\(300\\)\u003c/var\u003e meters east to visit a temple.\u003c/li\u003e\r\n\u003cli\u003eQuery \u003cvar\u003e\\(2\\)\u003c/var\u003e: If we start from a point at a distance of \u003cvar\u003e\\(2000\\)\u003c/var\u003e meters from the west end of the road, the optimal move is first to walk \u003cvar\u003e\\(1000\\)\u003c/var\u003e meters west to visit a temple, then to walk \u003cvar\u003e\\(400\\)\u003c/var\u003e meters west to visit a shrine. We will pass by another temple on the way, but it is fine.\u003c/li\u003e\r\n\u003cli\u003eQuery \u003cvar\u003e\\(3\\)\u003c/var\u003e: If we start from a point at a distance of \u003cvar\u003e\\(899\\)\u003c/var\u003e meters from the west end of the road, the optimal move is first to walk \u003cvar\u003e\\(1\\)\u003c/var\u003e meter east to visit a temple, then to walk \u003cvar\u003e\\(300\\)\u003c/var\u003e meters west to visit a shrine.\u003c/li\u003e\r\n\u003cli\u003eQuery \u003cvar\u003e\\(4\\)\u003c/var\u003e: If we start from a point at a distance of \u003cvar\u003e\\(799\\)\u003c/var\u003e meters from the west end of the road, the optimal move is first to walk \u003cvar\u003e\\(199\\)\u003c/var\u003e meters west to visit a shrine, then to walk \u003cvar\u003e\\(200\\)\u003c/var\u003e meters west to visit a temple.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 2","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1 1 3\r\n1\r\n10000000000\r\n2\r\n9999999999\r\n5000000000\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e10000000000\r\n10000000000\r\n14999999998\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003cp\u003eThe road is quite long, and we may need to travel a distance that does not fit into a \u003cvar\u003e\\(32\\)\u003c/var\u003e-bit integer.\u003c/p\u003e\u003c/section\u003e\r\n"}}]}