problem_id
stringlengths
6
6
user_id
stringlengths
10
10
time_limit
float64
1k
8k
memory_limit
float64
262k
1.05M
problem_description
stringlengths
48
1.55k
codes
stringlengths
35
98.9k
status
stringlengths
28
1.7k
submission_ids
stringlengths
28
1.41k
memories
stringlengths
13
808
cpu_times
stringlengths
11
610
code_sizes
stringlengths
7
505
p03111
u969190727
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\nprint(dfs(0, 0, 0, 0))', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n \ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\nprint(dfs(0, 0, 0, 0))']
['Runtime Error', 'Accepted']
['s901285809', 's128496256']
[2940.0, 3188.0]
[18.0, 78.0]
[434, 437]
p03111
u997521090
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int,input().split())\nans = [[0, 0, 0, 0]]\nfor i in range(N): ans = [[p[j] + int(input()) * (i == j) for j in [0, 1, 2]] + [p[3]+(i < 3)] for p in ans for i in range(4)]\nprint(min(abs(p[0] - A) + abs(p[1] - B) + abs(p[2] - C) + p[3] * 10 - 30 for p in ans if min(p[:3]) > 0))', 'N,*A=map(int,input().split());a=[[0]*4];r=[0,1,2]\nfor i in range(N):l=int(input());a+=[[p[j]+l*(i==j)for j in r]+[p[3]+10]for i in r for p in a]\nprint(min(sum(abs(p[i]-A[i])for i in r)-30+p[3]for p in a if min(p[:3])>0))']
['Runtime Error', 'Accepted']
['s222719236', 's353560957']
[3180.0, 16756.0]
[18.0, 170.0]
[291, 220]
p03112
u001024152
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
["# D\nfrom bisect import bisect_right\nA,B,Q = map(int, input().split())\nINF = float('inf')\ns = [-INF] + [int(input()) for _ in range(A)] + [INF]\nt = [-INF] + [int(input()) for _ in range(A)] + [INF]\nfor q in range(Q):\n x = int(input())\n b,d = bisect_right(s, x), bisect_right(t, x)\n ans = INF\n for s_visit in [s[b-1], s[b]]:\n for t_visit in [t[d-1, t[d]]]:\n dist1 = abs(s_visit - x) + abs(t_visit - s_visit)\n dist2 = abs(t_visit - x) + abs(s_visit - t_visit)\n ans = min(ans, dist1, dist2)\n print(ans)", "# D\nfrom bisect import bisect_right\nimport sys\ninput = sys.stdin.readline\nA,B,Q = map(int, input().split())\nINF = float('inf')\ns = [-INF] + [int(input()) for _ in range(A)] + [INF]\nt = [-INF] + [int(input()) for _ in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b,d = bisect_right(s, x), bisect_right(t, x)\n ans = INF\n for s_visit in [s[b-1], s[b]]:\n for t_visit in [t[d-1], t[d]]:\n dist1 = abs(s_visit - x) + abs(t_visit - s_visit)\n dist2 = abs(t_visit - x) + abs(s_visit - t_visit)\n ans = min(ans, dist1, dist2)\n print(ans)"]
['Runtime Error', 'Accepted']
['s885594130', 's077235790']
[11664.0, 12816.0]
[334.0, 942.0]
[553, 591]
p03112
u011634450
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['def get_nearest(point, lst):\n shortest = 1000000000000000\n nearest = float("inf")\n for x in lst:\n dist = abs(x - point)\n if dist < shortest:\n shortest = dist\n nearest = x\n return nearest\n\ndef exist_between(a, b, lst):\n for x in lst:\n if a <= x and x <= b:\n return True\n else:\n return False\n\nA, B, Q = [int(x) for x in input().split(" ")]\na = []\nb = []\nfor i in range(A):\n a.append(int(input()))\nfor i in range(B):\n b.append(int(input()))\nfor i in range(Q):\n q = int(input())\n nearest_a = get_nearest(q, a)\n nearest_b = get_nearest(q, b)\n# print(q, nearest_a, nearest_b)\n farer = nearest_b if abs(nearest_a - q) < abs(nearest_b - q) else nearest_a\n nearer = nearest_a if abs(nearest_a - q) < abs(nearest_b - q) else nearest_b\n not_farer_list = a if abs(nearest_a - q) < abs(nearest_b - q) else b\n if exist_between(q, farer, not_farer_list):\n print(abs(farer - q))\n else:\n print(abs(nearer - q) + abs(farer - nearer))\n', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\nfor S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s508522283', 's748450530', 's763119100', 's361180485']
[11052.0, 11668.0, 17552.0, 13964.0]
[2104.0, 742.0, 1992.0, 1705.0]
[1041, 464, 484, 476]
p03112
u016128476
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['# input\nA, B, Q = map(int, input().split())\nS, T, X = [], [], []\nfor _ in range(A):\n S.append(int(input()))\n\nfor _ in range(B):\n T.append(int(input()))\n\nfor _ in range(Q):\n X.append(int(input()))\n\n# end of world\nEOW = 10 ** 10\n\n# boundary info\ntbounds = [(T[i+1] + T[i]) // 2 for i in range(B-1)]\nsbounds = [(S[i+1] + S[i]) // 2 for i in range(A-1)]\n\n\ntbounds.insert(0, 0)\ntbounds.append(EOW)\nsbounds.insert(0, 0)\nsbounds.append(EOW)\n\n# temple to shrine\nttos = []\ncur = 0\nfor i in range(B):\n while True:\n if T[i] <= sbounds[cur]:\n break\n cur += 1\n ttos.append(cur-1)\n\n# shrine to temple\nstot = []\ncur = 0\nfor i in range(A):\n while True:\n if S[i] <= tbounds[cur]:\n break\n cur += 1\n stot.append(cur-1)\n\n \nfor x in X:\n\tprint(0)\n\n', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)']
['Wrong Answer', 'Accepted']
['s739001645', 's994925598']
[31544.0, 12800.0]
[720.0, 1695.0]
[960, 476]
p03112
u021548497
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import sys\n\ndef main():\n input = sys.stdin.readline\n a, b, q = map(int, input().split())\n s = [0]*a\n for i in range(a):\n s[i] = int(input())\n \n t = [0]*b\n for i in range(b):\n t[i] = int(input())\n\n s_near = [0]*a\n k = 0\n for i in range(a):\n if k == b-1:\n s_near[i] = abs(s[i]-t[b-1])\n continue\n while True:\n sub = min([abs(s[i]-t[k]), abs(s[i]-t[k+1])])\n if sub == abs(s[i]-t[k+1]):\n k += 1\n if k == b-1:\n sub == abs(s[i]-t[k])\n break\n continue\n else:\n s_near[i] = sub\n break\n \n t_near = [0]*b\n k = 0\n for i in range(b):\n if k == a-1:\n t_near[i] = abs(t[i]-s[a-1])\n continue\n while True:\n sub = min([abs(t[i]-s[k]), abs(t[i]-s[k+1])])\n if sub == abs(t[i]-s[k+1]):\n k += 1\n if k == a-1:\n sub == abs(t[i]-s[k])\n break\n continue\n else:\n sub == abs(t[i]-s[k+1])\n break\n \n for i in range(q):\n x = int(input())\n if x <= s[0]:\n sub1 = s[0]-x+s_near[0]\n elif x >= s[a-1]:\n sub1 = x-s[a-1]+s_near[a-1]\n else:\n l, r = 0, a\n while r-l > 1:\n k = (r+l)//2\n if x <= s[k]:\n r = k\n else:\n l = k\n sub1 = min([s[r]-x+s_near[r], x-s[l]+s_near[l]])\n \n if x <= t[0]:\n sub2 = t[0]-x+t_near[0]\n elif x >= t[b-1]:\n sub2 = x-t[b-1]+t_near[b-1]\n else:\n l, r = 0, b\n while r-l > 1:\n k = (r+l)//2\n if x <= t[k]:\n r = k\n else:\n l = k\n sub2 = min([t[r]-x+t_near[r], x-t[l]+t_near[l]])\n ans = min([sub1, sub2])\n print(ans)\n\n\nif __name__ == "__main__":\n main()', 'import sys\nimport bisect\n\ndef main():\n input = sys.stdin.readline\n inf = pow(10, 18)\n a, b, q = map(int, input().split())\n s = [-inf]+[int(input()) for _ in range(a)]+[inf]\n t = [-inf]+[int(input()) for _ in range(b)]+[inf]\n \n for _ in range(q):\n x = int(input())\n i = bisect.bisect_left(s, x)\n j = bisect.bisect_left(t, x)\n ans = inf\n for l in range(2):\n for m in range(2):\n sub = min([abs(x-s[i+l]), abs(x-t[j+m])])+abs(s[i+l]-t[j+m])\n if ans > sub:\n ans = sub\n print(ans)\n\nif __name__ == "__main__":\n main()', 'import sys\nimport bisect\n\ndef main():\n input = sys.stdin.readline\n inf = pow(10, 18)\n a, b, q = map(int, input().split())\n s = [-inf]+[int(input()) for _ in range(a)]+[inf]\n t = [-inf]+[int(input()) for _ in range(b)]+[inf]\n \n for _ in range(q):\n x = int(input())\n i = bisect.bisect_left(s, x)\n j = bisect.bisect_left(t, x)\n ans = inf\n for l in range(-1, 1):\n for m in range(-1, 1):\n sub = min([abs(x-s[i+l]), abs(x-t[j+m])])+abs(s[i+l]-t[j+m])\n if ans > sub:\n ans = sub\n print(ans)\n\nif __name__ == "__main__":\n main()']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s128611843', 's649465382', 's012707005']
[20120.0, 12432.0, 12800.0]
[1516.0, 808.0, 899.0]
[1676, 564, 572]
p03112
u028217518
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['read = input\n# read = Read(False, """\n# 1 1 3\n# 1\n# 10000000000\n# 2\n# 9999999999\n# 5000000000\n# """).read\nA,B,Q = list(map(int, read().split(\' \')))\narrA = list(map(int, [read() for i in range(A)]))\narrB = list(map(int, [read() for i in range(B)]))\narrQ = list(map(int, [read() for i in range(Q)]))\narrA.sort()\narrB.sort()\nimport bisect\ndef cs(x, arr):\n al = bisect.bisect_left(arr, x)\n return list(map(lambda i: arr[i], filter(lambda i:i>=0 and i< len(arr), range(al, al + 2))))\n\ndef same_s(da,db):\n da = da / abs(da)\n db = db / abs(db)\n return da*db>0\n \ndef t(q,a,b):\n da = q - a\n db = q - b\n if(min(abs(da), abs(db)) == 0):\n return max(abs(da), abs(db))\n if same_s(da, db):\n return max(abs(da), abs(db))\n else :\n return 2*min(abs(da), abs(db)) + max(abs(da), abs(db))\nfor q in arrQ:\n optA = cs(q, arrA)\n optB = cs(q, arrB)\n ret = 10 ** 11\n for a in optA:\n for b in optB:\n ret = min(ret, t(q, a,b))\n print(ret)', 'read = input\nread = Read(False, """\n1 1 3\n1\n10000000000\n2\n9999999999\n5000000000\n""").read\nA,B,Q = list(map(int, read().split(\' \')))\narrA = list(map(int, [read() for i in range(A)]))\narrB = list(map(int, [read() for i in range(B)]))\narrQ = list(map(int, [read() for i in range(Q)]))\narrA.sort()\narrB.sort()\nimport bisect\ndef cs(x, arr):\n al = bisect.bisect_left(arr, x)\n return list(map(lambda i: arr[i], filter(lambda i:i>=0 and i< len(arr), range(al-1, al + 2))))\ndef same_s(da,db):\n da = da / abs(da)\n db = db / abs(db)\n return da*db>0\n \ndef t(q,a,b):\n da = q - a\n db = q - b\n if(min(abs(da), abs(db)) == 0):\n return max(abs(da), abs(db))\n if same_s(da, db):\n return max(abs(da), abs(db))\n else :\n return 2*min(abs(da), abs(db)) + max(abs(da), abs(db))\nfor q in arrQ:\n optA = cs(q, arrA)\n optB = cs(q, arrB)\n ret = 10 ** 11\n for a in optA:\n for b in optB:\n ret = min(ret, t(q, a,b))\n print(ret)', 'import bisect\nread = input\nbisect_right = bisect.bisect_right\n# @ see https://docs.python.org/zh-cn/3/library/bisect.html\na ,b , q = map(int, read().split())\nINF = 10**18\nA =[-INF] + [int(read()) for i in range(a)] +[INF]\nB =[-INF] + [int(read()) for i in range(b)] +[INF]\nA.sort()\nB.sort()\ntry:\n for i in range(q):\n x = int(read())\n sa = bisect_right(A, x)\n sb = bisect_right(B, x)\n ans = INF\n for pa in [A[sa - 1 ], A[sa]]:\n for pb in [B[sb - 1 ], B[sb]]:\n d1 = abs(x - pa) + abs(pa - pb)\n d2 = abs(x - pb) + abs(pb - pa)\n ans = min(ans, d1, d2)\n print(ans)\nexcept:\n print(x, sa, sb)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s254366772', 's661311279', 's872983522']
[22836.0, 3064.0, 12800.0]
[1790.0, 18.0, 1716.0]
[998, 983, 689]
p03112
u029234056
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nA,B,Q=map(int,input().split(" "))\nINF=10**18\nS=[-INF]+[int(input()) for _ in range(A)]+[INF]\nprint(S)\nT=[-INF]+[int(input()) for _ in range(B)]+[INF]\nfor _ in range(Q):\n x=int(input())\n a,b=bisect.bisect_right(S,x),bisect.bisect_right(T,x)\n res=INF\n for e in [S[a-1],S[a]]:\n for g in [T[b-1],T[b]]:\n d=abs(e-x)+abs(e-g)\n d1=abs(g-x)+abs(g-e)\n res=min(res,d,d1)\n print(res)\n print(res)', 'import bisect\nA,B,Q=map(int,input().split())\nINF=10**18\ns=[-INF]+[int(input()) for i in range(A)]+[INF]\nt=[-INF]+[int(input()) for i in range(B)]+[INF]\nfor q in range(Q):\n x=int(input())\n b,d=bisect.bisect_right(s,x),bisect.bisect_right(t,x)\n res=INF\n for S in [s[b-1],s[b]]:\n for T in [t[d-1],t[d]]:\n d1,d2=abs(S-x)+abs(S-T),abs(T-x)+abs(S-T)\n res=min(res,d1,d2)\n print(res)']
['Wrong Answer', 'Accepted']
['s892664838', 's898487750']
[19800.0, 14092.0]
[2105.0, 1686.0]
[464, 419]
p03112
u036340997
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\na, b, q = map(int, input().split())\ninf = 10**18\ns = [-inf] + [int(input()) for i in range(a)] + [inf]\nt = [-inf] + [int(input()) for i in range(b)] + [inf]\n\nfor i in range(q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect_right(t, x)\n res = inf\n for S in [s[b-1], s[b]]:\n for T in [t[b-1], t[b]]:\n d1, d2 = abs(S-x) + abs(T-S), abs(T-x) + abs(S-T)\n res = min(d1, d2, res)\n print(res)', 'import bisect\na, b, q = map(int, input().split())\ninf = 10**18\ns = [-inf] + [int(input()) for i in range(a)] + [inf]\nt = [-inf] + [int(input()) for i in range(b)] + [inf]\n\nfor i in range(q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = inf\n for S in [s[b-1], s[b]]:\n for T in [t[b-1], t[b]]:\n d1, d2 = abs(S-x) + abs(T-S), abs(T-x) + abs(S-T)\n res = min(d1, d2, res)\n print(res)\n', 'import bisect\na, b, q = map(int, input().split())\ninf = 10**18\ns = [-inf] + [int(input()) for i in range(a)] + [inf]\nt = [-inf] + [int(input()) for i in range(b)] + [inf]\n\nfor i in range(q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = inf\n for S in [s[b-1], s[b]]:\n for T in [t[d-1], t[d]]:\n d1, d2 = abs(S-x) + abs(T-S), abs(T-x) + abs(S-T)\n res = min(d1, d2, res)\n print(res)\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s428819751', 's576411105', 's758360995']
[11740.0, 14336.0, 14340.0]
[334.0, 1727.0, 1735.0]
[430, 438, 438]
p03112
u046187684
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['def solve(string):\n a, b, q, *stx = map(int, string.split())\n s = sorted(stx[:a] + [-10**10, 2 * 10**10])\n t = sorted(stx[a:a + b] + [-10**10, 2 * 10**10])\n x = {_q: -1 for _q in stx[-q:]}\n i_s = 0\n i_t = 0\n for _x in sorted(x.keys()):\n while s[i_s] < _x:\n i_s += 1\n while t[i_t] < _x:\n i_t += 1\n l_s, r_s = s[i_s - 1], s[i_s]\n l_t, r_t = t[i_t - 1], t[i_t]\n r_max = max(r_s, r_t)\n r_min = min(r_s, r_t)\n l_max = max(l_s, l_t)\n l_min = min(l_s, l_t)\n\n x[_x] = min([r_max - _x, _x - l_min, r_min - l_max + min(r_min - _x, _x - l_max)])\n return "\\n".join([str(x[_x]) for _x in stx[-q:]])\n\n\nif __name__ == \'__main__\':\n n, m, l = map(int, input().split())\n print(solve(\'{} {}\\n\'.format(n, m, l) + \'\\n\'.join([input() for _ in range(n + m + l)])))\n', 'from bisect import bisect_left\n\n\ndef solve(string):\n a, b, q, *stx = map(int, string.split())\n s = [-10**10] + stx[:a] + [2 * 10**10]\n t = [-10**10] + stx[a:a + b] + [2 * 10**10]\n \n ans = []\n i_s = 0\n i_t = 0\n for _x in stx[-q:]:\n """\n while s[i_s] < _x:\n i_s += 1\n while t[i_t] < _x:\n i_t += 1\n """\n i_s, i_t = bisect_left(s, _x), bisect_left(t, _x)\n ls, rs = _x - s[i_s - 1], s[i_s] - _x\n lt, rt = _x - t[i_t - 1], t[i_t] - _x\n r_max = max(rs, rt)\n l_min = _x - min(ls, lt)\n """\n x[_x] = min([\n r_max - _x, _x - l_min, rt - ls + min(rt - _x, _x - ls),\n rs - lt + min(rs - _x, _x - lt)\n ])\n """\n ans.append(str(min([r_max, l_min, rt - ls + min(rt, ls), rs - lt + min(rs, lt)])))\n # return "\\n".join([str(x[_x]) for _x in stx[-q:]])\n return "\\n".join(ans)\n\n\nif __name__ == \'__main__\':\n n, m, l = map(int, input().split())\n print(solve(\'{} {} {}\\n\'.format(n, m, l) + \'\\n\'.join([input() for _ in range(n + m + l)])))\n', 'from bisect import bisect_left\n\n\ndef solve(string):\n a, b, q, *stx = map(int, string.split())\n bignum = 3 * 10**10\n s = [-bignum] + stx[:a] + [bignum]\n t = [-bignum] + stx[a:a + b] + [bignum]\n ans = []\n for _x in stx[-q:]:\n i, j = bisect_left(s, _x), bisect_left(t, _x)\n ls, rs = _x - s[i - 1], s[i] - _x\n lt, rt = _x - t[j - 1], t[j] - _x\n ans.append(str(min(max(rs, rt), max(ls, lt), rt + ls + min(rt, ls),\n rs + lt + min(rs, lt))))\n return "\\n".join(ans)\n\n\nif __name__ == \'__main__\':\n n, m, l = map(int, input().split())\n print(solve(\'{} {} {}\\n\'.format(n, m, l) + \'\\n\'.join([input() for _ in range(n + m + l)])))\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s108323057', 's573787370', 's171482414']
[67232.0, 39528.0, 39512.0]
[1307.0, 767.0, 772.0]
[857, 1107, 698]
p03112
u052499405
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\n\nA, B, Q = [int(i) for i in input().split()]\n\ns = [-10**12] + [int(input()) for i in range(A)] + [10**12]\nt = [-10**12] + [int(input()) for i in range(B)] + [10**12]\nx = [int(input()) for i in range(Q)]\n\nfor item in x:\n b, d = bisect.bisect_left(s, item), bisect.bisect_left(t, item)\n min_value = 10**12\n for item_a in [s[a], s[a+1]]:\n for item_c in [t[c], t[c+1]]:\n pata = abs(item_a - item) + abs(item_a - item_c)\n patb = abs(item_c - item) + abs(item_a - item_c)\n min_value = min(min_value, pata, patb)\n print(min_value)\n', 'import bisect\n\nA, B, Q = [int(i) for i in input().split()]\n\ns = [-10**12] + [int(input()) for i in range(A)] + [10**12]\nt = [-10**12] + [int(input()) for i in range(B)] + [10**12]\nx = [int(input()) for i in range(Q)]\n\nfor item in x:\n a, c = bisect.bisect_left(s, item), bisect.bisect_left(t, item)\n min_value = 10**12\n for item_a in [s[a-1], s[a]]:\n for item_c in [t[c-1], t[c]]:\n pata = abs(item_a - item) + abs(item_a - item_c)\n patb = abs(item_c - item) + abs(item_a - item_c)\n min_value = min(min_value, pata, patb)\n print(min_value)\n']
['Runtime Error', 'Accepted']
['s614190020', 's365476415']
[14908.0, 16188.0]
[485.0, 1123.0]
[590, 590]
p03112
u054825571
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['from bisect import bisect_left\n\nA,B,Q=map(int,input().split())\nS=[int(input()) for i in range(A)]\nT=[int(input()) for i in range(B)]\nfor i in range(Q):\n x=int(input())\n si=bisect_left(S,x)\n ti=bisect_left(T,x)\n if 0<si<A and 0<ti<B:\n sl,sr=abs(x-S[si-1]),abs(x-S[si])\n tl,tr=abs(x-T[ti-1]),abs(x-T[ti])\n print(min(max(sr,tr),max(sl,tl),sl+tr+min(sl,tr),sr+tl+min(sr,tl)))\n elif si==0 and ti==0:\n sr=abs(x-S[si])\n tr=abs(x-T[ti])\n print(sr,tr)\n elif si==A and ti==B:\n sl=abs(x-S[si-1]),abs(x-S[si])\n tl=abs(x-T[ti-1]),abs(x-T[ti])\n print(max(sl,tl))\n elif si==0 and ti==B:\n sr=abs(x-S[si])\n tl=abs(x-T[ti-1])\n print(sr+tl+min(sr,tl))\n elif si==A and ti==0:\n sl=abs(x-S[si-1])\n tr=abs(x-T[ti])\n print(sl+tr+min(sl,tr))\n elif si==0:\n sr=abs(x-S[si])\n tl,tr=abs(x-T[ti-1]),abs(x-T[ti])\n print(min(max(sr,tr),sr+tl+min(sr,tl)))\n elif si==A:\n sl=abs(x-S[si-1])\n tl,tr=abs(x-T[ti-1]),abs(x-T[ti])\n print(min(max(sl,tl),sl+tr+min(sl,tr)))\n elif ti==0:\n sl,sr=abs(x-S[si-1]),abs(x-S[si])\n tr=abs(x-T[ti])\n print(min(max(sr,tr),sl+tr+min(sl,tr)))\n elif ti==B:\n sl,sr=abs(x-S[si-1]),abs(x-S[si])\n tl=abs(x-T[ti-1])\n print(min(max(sl,tl),sr+tl+min(sr,tl)))', 'from bisect import bisect_left\n\nA,B,Q=map(int,input().split())\nS=[int(input()) for i in range(A)]\nT=[int(input()) for i in range(B)]\nfor i in range(Q):\n x=int(input())\n si=bisect_left(S,x)\n ti=bisect_left(T,x)\n if 0<si<A and 0<ti<B:\n sl,sr=abs(x-S[si-1]),abs(x-S[si])\n tl,tr=abs(x-T[ti-1]),abs(x-T[ti])\n print(min(max(sr,tr),max(sl,tl),sl+tr+min(sl,tr),sr+tl+min(sr,tl)))\n elif si==0 and ti==0:\n sr=abs(x-S[si])\n tr=abs(x-T[ti])\n print(max(sr,tr))\n elif si==A and ti==B:\n sl=abs(x-S[si-1])\n tl=abs(x-T[ti-1])\n print(max(sl,tl))\n elif si==0 and ti==B:\n sr=abs(x-S[si])\n tl=abs(x-T[ti-1])\n print(sr+tl+min(sr,tl))\n elif si==A and ti==0:\n sl=abs(x-S[si-1])\n tr=abs(x-T[ti])\n print(sl+tr+min(sl,tr))\n elif si==0:\n sr=abs(x-S[si])\n tl,tr=abs(x-T[ti-1]),abs(x-T[ti])\n print(min(max(sr,tr),sr+tl+min(sr,tl)))\n elif si==A:\n sl=abs(x-S[si-1])\n tl,tr=abs(x-T[ti-1]),abs(x-T[ti])\n print(min(max(sl,tl),sl+tr+min(sl,tr)))\n elif ti==0:\n sl,sr=abs(x-S[si-1]),abs(x-S[si])\n tr=abs(x-T[ti])\n print(min(max(sr,tr),sl+tr+min(sl,tr)))\n elif ti==B:\n sl,sr=abs(x-S[si-1]),abs(x-S[si])\n tl=abs(x-T[ti-1])\n print(min(max(sl,tl),sr+tl+min(sr,tl)))']
['Runtime Error', 'Accepted']
['s555700637', 's196898777']
[16876.0, 16820.0]
[932.0, 940.0]
[1369, 1348]
p03112
u062459048
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nA,B,Q = map(int, input().split())\nS,T,X = [],[],[]\nfor i in range(A):\n S[i] = int(input())\nfor i in range(B):\n T[i] = int(input())\nfor i in range(Q):\n X[i] = int(input())\n for i in range(Q):\n ans = []\n sin = bisect.bisect_left(S, X[i])\n if sin == 0:\n s1,s2 = S[sin], -(10**9)\n elif sin == A:\n s1,s2 = (10**9),S[sin-1]\n else:\n s1,s2 = S[sin],S[sin-1]\n tin = bisect.bisect_left(T, X[i])\n if tin == 0:\n t1,t2 = T[tin], -(10**9)\n elif tin == B:\n t1,t2 = (10**9),T[tin-1]\n else:\n t1,t2 = T[tin],T[tin-1]\n for j in [s1,s2]:\n for k in [t1,t2]:\n for l in [0,1]:\n if l ==0:\n ans.append(abs(j-X[i])+abs(k-j))\n else:\n ans.append(abs(k-X[i])+abs(j-k)) \n \n print(min(ans))', 'import bisect\nA,B,Q = map(int, input().split())\nS,T,X = [],[],[]\nfor i in range(A):\n S[i] = int(input())\nfor i in range(B):\n T[i] = int(input())\nfor i in range(Q):\n X[i] = int(input())\n\nfor i in range(Q):\n ans = []\n sin = bisect.bisect_left(S, X[i])\n if sin == 0:\n s1,s2 = S[sin], -(10**9)\n elif sin == A:\n s1,s2 = (10**9),S[sin-1]\n else:\n s1,s2 = S[sin],S[sin-1]\n tin = bisect.bisect_left(T, X[i])\n if tin == 0:\n t1,t2 = T[tin], -(10**9)\n elif tin == B:\n t1,t2 = (10**9),T[tin-1]\n else:\n t1,t2 = T[tin],T[tin-1]\n for j in [s1,s2]:\n for k in [t1,t2]:\n for l in [0,1]:\n if l ==0:\n ans.append(abs(j-X[i])+abs(k-j))\n else:\n ans.append(abs(k-X[i])+abs(j-k)) \n \n print(min(ans))\n', 'import bisect\nA,B,Q = map(int, input().split())\nS,T,X = [],[],[]\nfor i in range(A):\n S.append(int(input()))\nfor i in range(B):\n T.append(int(input()))\nfor i in range(Q):\n X.append(int(input()))\n\nfor i in range(Q):\n ans = []\n sin = bisect.bisect_left(S, X[i])\n if sin == 0:\n s1,s2 = S[sin], -(10**12)\n elif sin == A:\n s1,s2 = (10**12),S[sin-1]\n else:\n s1,s2 = S[sin],S[sin-1]\n tin = bisect.bisect_left(T, X[i])\n if tin == 0:\n t1,t2 = T[tin], -(10**12)\n elif tin == B:\n t1,t2 = (10**12),T[tin-1]\n else:\n t1,t2 = T[tin],T[tin-1]\n for j in [s1,s2]:\n for k in [t1,t2]:\n for l in [0,1]:\n if l ==0:\n ans.append(abs(j-X[i])+abs(k-j))\n else:\n ans.append(abs(k-X[i])+abs(j-k)) \n \n print(min(ans))\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s320959155', 's492705625', 's302263214']
[2940.0, 3064.0, 16152.0]
[17.0, 19.0, 1366.0]
[754, 755, 768]
p03112
u062655521
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\n\nA, B, Q = map(int, input().split())\n\nINF = 10 ** 18\ns = [-INF] + [int(input()) for _ in range(A)] + [INF]\nt = [-INF] + [int(input()) for _ in range(B)] + [INF]\n\nfor x in range(Q):\n b = bisect.bisect_right(s, x)\n d = disect.bisect_right(t, x)\n dist = 0\n for sb in [s[b - 1], s[b]]:\n for td in [t[d - 1], t[d]]:\n d1, d2 = abs(x - sb) + abs(sb - td), abs(x - td) + abs(td - sb)\n dist = min(dist, d1, d2)\n print(dist)', 'import bisect\n\nA, B, Q = map(int, input().split())\n\nINF = 10 ** 18\ns = [-INF] + [int(input()) for _ in range(A)] + [INF]\nt = [-INF] + [int(input()) for _ in range(B)] + [INF]\n\nfor i in range(Q):\n x = int(input())\n b = bisect.bisect_right(s, x)\n d = bisect.bisect_right(t, x)\n dist = 0\n for sb in [s[b - 1], s[b]]:\n for td in [t[d - 1], t[d]]:\n d1, d2 = abs(x - sb) + abs(sb - td), abs(x - td) + abs(td - sb)\n dist = min(dist, d1, d2)\n print(dist)', 'import bisect\n\nA, B, Q = map(int, input().split())\n\nINF = 10 ** 18\ns = [-INF] + [int(input()) for _ in range(A)] + [INF]\nt = [-INF] + [int(input()) for _ in range(B)] + [INF]\n\nfor x in range(Q):\n b = bisect.bisect_right(s, x)\n d = bisect.bisect_right(t, x)\n dist = 0\n for sb in [s[b - 1], s[b]]:\n for td in [t[d - 1], t[d]]:\n d1, d2 = abs(x - sb) + abs(sb - td), abs(x - td) + abs(td - sb)\n dist = min(dist, d1, d2)\n print(dist)', 'import bisect\n\nA, B, Q = map(int, input().split())\n\nINF = 10 ** 18\ns = [-INF] + [int(input()) for _ in range(A)] + [INF]\nt = [-INF] + [int(input()) for _ in range(B)] + [INF]\n\nfor i in range(Q):\n x = int(input())\n b = bisect.bisect_right(s, x)\n d = bisect.bisect_right(t, x)\n dist = INF\n for sb in [s[b - 1], s[b]]:\n for td in [t[d - 1], t[d]]:\n d1, d2 = abs(x - sb) + abs(sb - td), abs(x - td) + abs(td - sb)\n dist = min(dist, d1, d2)\n print(dist)']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s234424199', 's582193178', 's597161809', 's430715670']
[11664.0, 13848.0, 11928.0, 13968.0]
[336.0, 1726.0, 907.0, 1771.0]
[446, 465, 446, 467]
p03112
u065188401
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['r i in range(A):\n S.append(int(input()))\n\nS = [-INF] + S + [INF]\n\nT = []\nfor i in range(B):\n T.append(int(input()))\n\nT = [-INF] + T + [INF]\n\n\nfor i in range(Q):\n x = int(input())\n \n d, b = bisect.bisect_right(S, x), bisect.bisect_right(T, x)\n \n res = INF\n for s in [S[d - 1], S[d]]:\n for t in [T[b - 1], T[b]]:\n res = min(res, \n abs(s - x) + abs(s - t),\n abs(t - x) + abs(s - t))\n \n print(res)', 'import bisect\nA,B,Q =map(int, input().split())\n\nINF = 10 ** 18\nS = []\nfor i in range(A):\n S.append(int(input()))\n\nS = [-INF] + S + [INF]\n\nT = []\nfor i in range(B):\n T.append(int(input()))\n\nT = [-INF] + T + [INF]\n\n\nfor i in range(Q):\n x = int(input())\n \n d, b = bisect.bisect_right(S, x), bisect.bisect_right(T, x)\n \n res = INF\n for s in [S[d - 1], S[d]]:\n for t in [T[b - 1], T[b]]:\n res = min(res, \n abs(s - x) + abs(s - t),\n abs(t - x) + abs(s - t))\n \n print(res)']
['Runtime Error', 'Accepted']
['s375474163', 's021958914']
[2940.0, 13584.0]
[17.0, 1730.0]
[491, 563]
p03112
u067729694
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['A, B, Q = map(int, input().split())\ns = []\nt = []\nx = []\nfor _ in range(A):\n s.append(int(input()))\nfor _ in range(B):\n t.append(int(input()))\nfor _ in range(Q):\n x.append(int(input()))\n\nimport sys\nINT_MAX = sys.maxsize\ns.insert(0, -1 * INT_MAX)\ns.append(INT_MAX)\nt.insert(0, -1 * INT_MAX)\nt.append(INT_MAX)\n\nimport bisect\nfor xi in x:\n #print(xi)\n si = bisect.bisect_right(s, xi)\n #si = 0\n #for si, v in enumerate(s):\n \n # break\n ti = bisect.bisect_right(s, xi)\n #ti = 0\n #for ti, v in enumerate(t):\n \n # break\n #print(si, ti)\n sa = s[si]\n ta = t[ti]\n sb = s[si-1]\n tb = t[ti-1]\n #print(sa, sb,ta,tb)\n ans = min([\n abs(xi-sa)+abs(sa-ta),\n abs(xi-sa)+abs(sa-tb),\n abs(xi-sb)+abs(sb-ta),\n abs(xi-sb)+abs(sb-tb),\n abs(xi-ta)+abs(ta-sa),\n abs(xi-ta)+abs(ta-sb),\n abs(xi-tb)+abs(tb-sa),\n abs(xi-tb)+abs(tb-sb)\n ])\n print(ans)', 'A, B, Q = map(int, input().split())\ns = []\nt = []\nx = []\nfor _ in range(A):\n s.append(int(input()))\nfor _ in range(B):\n t.append(int(input()))\nfor _ in range(Q):\n x.append(int(input()))\n\nimport sys\nINT_MAX = sys.maxsize\ns.insert(0, -1 * INT_MAX)\ns.append(INT_MAX)\nt.insert(0, -1 * INT_MAX)\nt.append(INT_MAX)\n\nimport bisect\nfor xi in x:\n #print(xi)\n si = bisect.bisect_right(s, xi)\n #si = 0\n #for si, v in enumerate(s):\n \n # break\n ti = bisect.bisect_right(t, xi)\n #ti = 0\n #for ti, v in enumerate(t):\n \n # break\n #print(si, ti)\n sa = s[si]\n ta = t[ti]\n sb = s[si-1]\n tb = t[ti-1]\n #print(sa, sb,ta,tb)\n ans = min([\n abs(xi-sa)+abs(sa-ta),\n abs(xi-sa)+abs(sa-tb),\n abs(xi-sb)+abs(sb-ta),\n abs(xi-sb)+abs(sb-tb),\n abs(xi-ta)+abs(ta-sa),\n abs(xi-ta)+abs(ta-sb),\n abs(xi-tb)+abs(tb-sa),\n abs(xi-tb)+abs(tb-sb)\n ])\n print(ans)']
['Runtime Error', 'Accepted']
['s182729953', 's399838991']
[16152.0, 16152.0]
[1026.0, 1044.0]
[990, 990]
p03112
u094191970
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import numpy as np\nA, B, Q = map(int, input().split())\n\ns_list = [int(input()) for a in range(A)]\nt_list = [int(input()) for b in range(B)]\nx_list = [int(input()) for q in range(Q)]\n\nfor x in x_list:\n near_s = np.abs(np.array(s_list) - x).argmin()\n near_t = np.abs(np.array(t_list) - x).argmin()\n\n if s_list[near_s] < t_list[near_t]:\n next_x = s_list[near_s]\n near_t2 = np.abs(np.array(t_list) - next_x).argmin()\n print(abs(x - s_list[near_s] + abs(next_x - t_list[near_t2])))\n\n elif s_list[near_s] > t_list[near_t]:\n next_x = t_list[near_t]\n near_s2 = np.abs(np.array(s_list) - next_x).argmin()\n print(abs(x - t_list[near_t] + abs(next_x - s_list[near_s2])))\n else:\n next_x1 = s_list[near_s]\n next_x2 = t_list[near_t]\n near_t2 = np.abs(np.array(t_list) - next_x).argmin()\n near_s2 = np.abs(np.array(s_list) - next_x).argmin()\n if abs(x - s_list[near_s] + abs(next_x - t_list[near_t2])) < abs(x - t_list[near_t] + abs(next_x - s_list[near_s2])):\n print(abs(x - s_list[near_s] + abs(next_x - t_list[near_t2])))\n else:\n print(abs(x - t_list[near_t] + abs(next_x - s_list[near_s2])))', 'A, B, Q = map(int, input().split())\ns_list = [int(input()) for a in range(A)]\nt_list = [int(input()) for b in range(B)]\nx_list = [int(input()) for q in range(Q)]\n\nfor x in x_list:\n s_distance = min(list(map(lambda n: abs(n - x), s_list)))\n s_index = list(map(lambda n: abs(n - x), s_list)).index(s_distance)\n t_distance = min(list(map(lambda n: abs(n - x), t_list)))\n t_index = list(map(lambda n: abs(n - x), t_list)).index(t_distance)\n if s_distance < t_distance:\n next_x = s_list[s_index]\n t_distance_2 = min(list(map(lambda n: abs(n - next_x), t_list)))\n print(s_distance + t_distance_2)\n elif s_distance > t_distance:\n next_x = t_list[t_index]\n s_distance_2 = min(list(map(lambda n: abs(n - next_x), s_list)))\n print(t_distance + s_distance_2)\n else:\n next_x_1 = s_list[s_index]\n next_x_2 = t_list[t_index]\n s_distance_2 = min(list(map(lambda n: abs(n - next_x_2), s_list)))\n t_distance_2 = min(list(map(lambda n: abs(n - next_x_1), t_list)))\n if s_distance + t_distance_2 < s_distance_2 + t_distance:\n print(s_distance + t_distance_2)\n else:\n print(t_distance + s_distance_2)', 'from bisect import bisect\n\na,b,q=map(int,input().split())\nINF=10**18\ns=[-INF]+[int(input()) for i in range(a)]+[INF]\nt=[-INF]+[int(input()) for i in range(b)]+[INF]\n\nfor i in range(q):\n x=int(input())\n s_inx=bisect(s,x)\n t_inx=bisect(t,x)\n\n s_l=s[s_inx-1]\n s_r=s[s_inx]\n\n t_l=t[t_inx-1]\n t_r=t[t_inx]\n\n ans=10**18\n for i in [s_l,s_r]:\n for j in [t_l,t_r]:\n d1=abs(i-x)+abs(j-i)\n d2=abs(j-x)+abs(i-j)\n ans=min(ans,d1,d2)\n\n print(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s046335785', 's276563544', 's075017770']
[26820.0, 19004.0, 17424.0]
[2109.0, 2105.0, 1116.0]
[1201, 1207, 460]
p03112
u104282757
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['# D\nfrom bisect import bisect_left\nA, B, Q = map(int, input().split())\n\ns_list = [0]*A\nt_list = [0]*B\nq_list = [0]*Q\n\nfor i in range(A):\n s_list[i] = int(input())\nfor i in range(B):\n t_list[i] = int(input())\nfor i in range(Q):\n q_list[i] = int(input())\n \ndef query_dist(q):\n res = 10**11\n \n ind_s = bisect_left(s_list, q)\n if ind_s != len(s_list):\n s = s_list[ind_s]\n ind_t = bisect_left(t_list, s)\n if ind_t != len(t_list):\n t = t_list[ind_t]\n res = min(res, abs(s-q)+abs(t-s))\n if ind_t != 0:\n t = t_list[ind_t-1]\n res = min(res, abs(s-q)+abs(t-s))\n if ind_s != 0:\n s = s_list[ind_s-1]\n ind_t = bisect_left(t_list, s)\n if ind_t != len(t_list):\n t = t_list[ind_t]\n res = min(res, abs(s-q)+abs(t-s))\n if ind_t != 0:\n t = t_list[ind_t-1]\n res = min(res, abs(s-q)+abs(t-s))\n \n ind_t = bisect_left(t_list, q)\n if ind_t != len(t_list):\n t = t_list[ind_t]\n ind_s = bisect_left(s_list, t)\n if ind_s != len(s_list):\n s = s_list[ind_s]\n res = min(res, abs(t-q)+abs(s-t))\n if ind_s != 0:\n s = s_list[ind_s-1]\n res = min(res, abs(t-q)+abs(s-t))\n if ind_t != len(t_list):\n t = t_list[ind_t-1]\n ind_s = bisect_left(s_list, t)\n if ind_s != len(s_list):\n s = s_list[ind_s]\n res = min(res, abs(t-q)+abs(s-t))\n if ind_s != 0:\n s = s_list[ind_s-1]\n res = min(res, abs(t-q)+abs(s-t))\n return res\n\nfor q in q_list:\n print(query_dist(q))', '# D\nfrom bisect import bisect_left\nA, B, Q = map(int, input().split())\n\ns_list = [0]*A\nt_list = [0]*B\nq_list = [0]*Q\n\nfor i in range(A):\n s_list[i] = int(input())\nfor i in range(B):\n t_list[i] = int(input())\nfor i in range(Q):\n q_list[i] = int(input())\n \ndef query_dist(q):\n res = 10**11\n \n ind_s = bisect_left(s_list, q)\n if ind_s != len(s_list):\n s = s_list[ind_s]\n ind_t = bisect_left(t_list, s)\n if ind_t != len(t_list):\n t = t_list[ind_t]\n res = min(res, abs(s-q)+abs(t-s))\n if ind_t != 0:\n t = t_list[ind_t-1]\n res = min(res, abs(s-q)+abs(t-s))\n if ind_s != 0:\n s = s_list[ind_s-1]\n ind_t = bisect_left(t_list, s)\n if ind_t != len(t_list):\n t = t_list[ind_t]\n res = min(res, abs(s-q)+abs(t-s))\n if ind_t != 0:\n t = t_list[ind_t-1]\n res = min(res, abs(s-q)+abs(t-s))\n \n ind_t = bisect_left(t_list, q)\n if ind_t != len(t_list):\n t = t_list[ind_t]\n ind_s = bisect_left(s_list, t)\n if ind_s != len(s_list):\n s = s_list[ind_s]\n res = min(res, abs(t-q)+abs(s-t))\n if ind_s != 0:\n s = s_list[ind_s-1]\n res = min(res, abs(t-q)+abs(s-t))\n if ind_t != 0:\n t = t_list[ind_t-1]\n ind_s = bisect_left(s_list, t)\n if ind_s != len(s_list):\n s = s_list[ind_s]\n res = min(res, abs(t-q)+abs(s-t))\n if ind_s != 0:\n s = s_list[ind_s-1]\n res = min(res, abs(t-q)+abs(s-t))\n return res\n\nfor q in q_list:\n print(query_dist(q))']
['Wrong Answer', 'Accepted']
['s733560700', 's696438201']
[16148.0, 18024.0]
[1352.0, 1496.0]
[1666, 1656]
p03112
u106778233
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect,sys \ninput=sys.stdin.readline \na,b,Q=map(int,input().split())\nINF=10**18\ns=[-INF]+[int(input()) for _ in range(A)]+[INF]\nt=[-INF]+[int(input()) for _ in range(B)]+[INF]\nfor q in range(Q):\n x=int(input())\n b,d=bisect.bisect_right(s,x),bisect.bisect_right(t,x)\n res=INF \n for S in [s(b-1),s(b)]:\n for T in [t(d-1),t(d)]:\n d1,d2=abs(S-x)+abs(T-S),abs(T-x)+abs(T-S)\n res=min(res,d1,d2)\n print(res)', 'import bisect,sys \ninput=sys.stdin.readline \na,b,Q=map(int,input().split())\nINF=10**18\ns=[-INF]+[int(input()) for _ in range(a)]+[INF]\nt=[-INF]+[int(input()) for _ in range(b)]+[INF]\nfor q in range(Q):\n x=int(input())\n b,d=bisect.bisect_right(s,x),bisect.bisect_right(t,x)\n res=INF \n for S in [s(b-1),s(b)]:\n for T in [t(d-1),t(d)]:\n d1,d2=abs(S-x)+abs(T-S),abs(T-x)+abs(T-S)\n res=min(res,d1,d2)\n print(res)', 'import bisect,sys \ninput=sys.stdin.readline \na,b,Q=map(int,input().split())\nINF=10**18\ns=[-INF]+[int(input()) for _ in range(a)]+[INF]\nt=[-INF]+[int(input()) for _ in range(b)]+[INF]\nfor q in range(Q):\n x=int(input())\n b,d=bisect.bisect_right(s,x),bisect.bisect_right(t,x)\n res=INF \n for S in [s[b-1],s[b]]:\n for T in [t[d-1],t[d]]:\n d1,d2=abs(S-x)+abs(T-S),abs(T-x)+abs(T-S)\n res=min(res,d1,d2)\n print(res)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s537295437', 's888419955', 's659503656']
[3064.0, 11664.0, 12816.0]
[18.0, 104.0, 905.0]
[451, 451, 451]
p03112
u117348081
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\n\nA,B,Q = map(int, input().split())\nINF = 10**18\n\ns =[-INF] + [int(input()) for i in range(A)] +[INF]\nt =[-INF] + [int(input()) for i in range(B)] +[INF]\n\nfor q in range(q):\n x = int(input())\n b,d =bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b-1], s[b]]:\n for T in [t[d-1], t[d]]:\n d1,d2 = abs(S-x)+abs(T-S),abs(T-x)+abs(S-T)\n res = min(res, d1,d2)\nprint(res)', 'import bisect\n\nA,B,Q = map(int, input().split())\nINF = 10**18\n\ns =[-INF] + [int(input()) for i in range(A)] +[INF]\nt =[-INF] + [int(input()) for i in range(B)] +[INF]\n\nfor q in range(q):\n x = int(input())\n b, d =bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b-1], s[b]]:\n for T in [t[d-1], t[d]]:\n d1,d2 = abs(S-x)+abs(T-S),abs(T-x)+abs(S-T)\n res = min(res, d1,d2)\n print(res)', 'import bisect\n\nA,B,Q = map(int, input().split())\nINF = 10**18\n\ns =[-INF] + [int(input()) for i in range(A)] +[INF]\nt =[-INF] + [int(input()) for i in range(B)] +[INF]\n\nfor q in range(Q):\n x = int(input())\n b, d =bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b-1], s[b]]:\n for T in [t[d-1], t[d]]:\n d1,d2 = abs(S-x)+abs(T-S),abs(T-x)+abs(S-T)\n res = min(res, d1,d2)\n print(res)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s430745549', 's667802796', 's222962549']
[11776.0, 11744.0, 14360.0]
[333.0, 374.0, 1702.0]
[446, 451, 451]
p03112
u129315407
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['\n\nsa = []\nta = []\nqa = []\nfor i in range(sn):\n sa.append(int(input()))\nfor i in range(tn):\n ta.append(int(input()))\nfor i in range(qn):\n qa.append(int(input()))\n\n\ndef find_nearest(q, al, s, e):\n if e - s < 2:\n d1 = abs(q - al[s])\n d2 = abs(q - al[e])\n if d1 < d2:\n return al[s]\n return al[e]\n idx = (e - s) // 2 + s\n if al[idx] == q:\n return al[idx]\n if al[idx] > q:\n return find_nearest(q, al, s, idx)\n return find_nearest(q, al, idx, e)\n\ndef find_range(q1, q2, al, s, e):\n if al[s] >= q1 and al[s] <= q2:\n return True\n if al[e] >= q1 and al[e] <= q2:\n return True\n if al[s] >= q2 or al[e] <= q1 or e - s < 2:\n return False\n idx = (e - s) // 2 + s\n if al[idx] < q1:\n return find_range(q1, q2, al, s, idx)\n return find_range(q1, q2, al, idx, e)\n\ndef move_cost(q, al, bl):\n mx = find_nearest(q, al, 0, len(al) - 1)\n min_x = min(mx, q)\n max_x = max(mx, q)\n if find_range(min_x, max_x, bl, 0, len(bl) - 1):\n return max_x - min_x\n\n mx2 = find_nearest(mx, bl, 0, len(bl) - 1)\n return (max_x - min_x) + abs(mx2 - mx)\n\nfor q in qa:\n a1 = move_cost(q, sa, ta)\n a2 = move_cost(q, ta, sa)\n print(min(a1, a2))\n', 'import bisect\nsn, tn, qn = map(int, input().split())\n\nLARGE = -100000000\nsa = []\nta = []\nqa = []\nfor i in range(sn):\n sa.append(int(input()))\nfor i in range(tn):\n ta.append(int(input()))\nfor i in range(qn):\n qa.append(int(input()))\n\ndef find_nearest(q, al, s, e):\n idx = bisect.bisect_right(al, q)\n if idx == 0:\n return [al[0], al[0]]\n if idx == len(al):\n return [al[idx - 1], al[idx - 1]]\n return [al[idx - 1], al[idx]]\n\ndef move_cost(q, al, bl):\n a1, a2 = find_nearest(q, al, 0, len(al) - 1)\n b1, b2 = find_nearest(q, bl, 0, len(bl) - 1)\n\n def calc(x1, x2, x3):\n y1 = min(x1, x2)\n y2 = max(x1, x2)\n if x3 >= y1 and x3 <= y2:\n return abs(x1 - x2)\n return abs(x1 - x2) + abs(x2 - x3)\n return min(\n calc(q, a1, b1),\n calc(q, a1, b2),\n calc(q, a2, b1),\n calc(q, a2, b2),\n calc(q, b1, a1),\n calc(q, b1, a2),\n calc(q, b2, a1),\n calc(q, b2, a2),\n )\n\nfor q in qa:\n print(move_cost(q, sa, ta))']
['Runtime Error', 'Accepted']
['s070704793', 's730166816']
[3064.0, 16168.0]
[18.0, 1434.0]
[1296, 1034]
p03112
u149284596
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect as bi\na,b,q = map(int,input().split())\ns = sorted([int(input()) for i in range(a) ])\nt = sorted([int(input()) for i in range(b) ])\nx = sorted([int(input()) for i in range(q) ])\n\nfor i in range(q):\n Q = x[i]\n ans_s = []\n ans_t = []\n ans_s.append(s[bi.bisect_left(s,Q)])\n ans_t.append(t[bi.bisect_left(t,Q)])\n ans = 10**11\n \n if bi.bisect_right(s,Q) == len(s):\n ans_s.append(s[bi.bisect_left(s,Q)-1])\n else:\n ans_s.append(s[bi.bisect_left(s,Q)])\n \n if bi.bisect_right(t,Q) == len(t):\n ans_t.append(t[bi.bisect_left(t,Q)-1])\n else:\n ans_t.append(t[bi.bisect_left(t,Q)])\n \n for i in range(2):\n for j in range(2):\n ans = max(ans,abs(ans_s[i]-Q)+abs(ans_s[i]-ans_t[j]),abs(ans_t[j]-Q)+abs(ans_s[i]-ans_t[j]))\n \n print(ans)', 'import bisect as bi\na,b,q = map(int,input().split())\ns = sorted([int(input()) for i in range(a) ])\nt = sorted([int(input()) for i in range(b) ])\nx = [int(input()) for i in range(q) ]\n\nfor i in range(q):\n Q = x[i]\n ans_s = []\n ans_t = []\n ans_s.append(s[bi.bisect_left(s,Q)-1])\n ans_t.append(t[bi.bisect_left(t,Q)-1])\n ans = 10**11\n \n if bi.bisect_right(s,Q) == len(s):\n ans_s.append(s[bi.bisect_left(s,Q)-1])\n else:\n ans_s.append(s[bi.bisect_left(s,Q)])\n \n if bi.bisect_right(t,Q) == len(t):\n ans_t.append(t[bi.bisect_left(t,Q)-1])\n else:\n ans_t.append(t[bi.bisect_left(t,Q)])\n \n for i in range(2):\n for j in range(2):\n ans = min(ans,abs(ans_s[i]-Q)+abs(ans_s[i]-ans_t[j]),abs(ans_t[j]-Q)+abs(ans_s[i]-ans_t[j]))\n \n print(ans)']
['Runtime Error', 'Accepted']
['s134785162', 's949271308']
[18696.0, 16160.0]
[1512.0, 1640.0]
[828, 824]
p03112
u167523937
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import sys\ndef calc_dist(xi,s,t):\n s_dif = []\n t_dif = []\n min_s_dif = sys.maxsize\n min_t_dif = sys.maxsize\n min_s = -1\n min_t = -1\n ls = len(s)\n lt = len(t)\n l = ls\n if ls<lt:\n l=lt\n temp_min_s_dif = 0\n temp_min_t_dif = 0\n result=0\n for i in range(l):\n if i < ls:\n temp_min_s_dif = abs(s[i]-xi)\n if min_s_dif > temp_min_s_dif:\n min_s_dif = temp_min_s_dif\n min_s = i\n if i < lt:\n temp_min_t_dif = abs(t[i]-xi)\n if min_t_dif > temp_min_t_dif:\n min_t_dif = temp_min_t_dif\n min_t = i\n #print(min_s_dif,min_t_dif,s[min_s],t[min_t])\n if min_s_dif < min_t_dif: \n if (s[min_s]<xi and xi<t[min_t]) or (t[min_t]<xi and xi<s[min_s]):\n result = 2*min_s_dif + min_t_dif\n else:\n result = min_t_dif\n else:\n if (s[min_s]<xi and xi<t[min_t]) or (t[min_t]<xi and xi<s[min_s]):\n result = 2*min_t_dif + min_s_dif\n else:\n result = min_s_dif\n return result\n\n"""\nA,B,Q = 1,1,3\ns=[1]\nt=[10000000000]\nx=[2,9999999999,5000000000]"""\nA,B,Q=map(int, input().split())\ns=[int(input()) for _ in range(A)]\nt=[int(input()) for _ in range(B)]\nx=[int(input()) for _ in range(Q)]\nfor xi in x:\n print(calc_dist(xi,s,t))', 'import bisect\nimport sys\nINF = 10**18\n\nA,B,Q=map(int, input().split())\ns=[-INF]+[int(input()) for _ in range(A)]+[INF]\nt=[-INF]+[int(input()) for _ in range(B)]+[INF]\nx=[int(input()) for _ in range(Q)]\ns.sort()\nt.sort()\n\nls = len(s)\nlt = len(t)\nfor xi in x:\n s2 = bisect.bisect_left(s,xi)\n s1=s2-1\n t1 = 0\n t2 = bisect.bisect_left(t,xi)\n t1=t2-1\n l1 = l2 = l3 = l4 = sys.maxsize\n l1 = max(abs(s[s1]-xi),abs(t[t1]-xi))\n l2 = max(abs(s[s2]-xi),abs(t[t2]-xi))\n if abs(s[s1]-xi)<abs(t[t1]-xi):\n l3 = 2*abs(s[s1]-xi) + abs(t[t2]-xi)\n else:\n l3 = 2*abs(t[t1]-xi) + abs(s[s2]-xi)\n if abs(s[s2]-xi)<abs(t[t2]-xi):\n l4 = 2*abs(s[s2]-xi) + abs(t[t1]-xi)\n else:\n l4 = 2*abs(t[t2]-xi) + abs(s[s1]-xi)\n l = [l1,l2,l3,l4]\n print(min(l))']
['Wrong Answer', 'Accepted']
['s111134314', 's780197670']
[15028.0, 17272.0]
[2104.0, 1052.0]
[1338, 933]
p03112
u169696482
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nA,B,Q=map(int,input().split())\nINF=10**18\nS=[-INF]+[int(input()) for i in range(A)]+[INF]\nT=[-INF]+[int(input()) for i in range(B)]+[INF]\nfor q in range(Q):\n x=int(input())\n i=bisect.bisect_right(S,x)\n j=bisect.bisect_right(T,x)\n d=INF\n print(i)\n for s in [S[i-1],S[i]]:\n for t in [T[j-1],T[j]]:\n d1=abs(s-x)+abs(s-t)\n d2=abs(t-x)+abs(s-t)\n d=min(d,d1,d2)\n print(d)', 'import bisect\nA,B,Q=map(int,input().split())\nINF=10**18\nS=[-INF]+[int(input()) for i in range(A)]+[INF]\nT=[-INF]+[int(input()) for i in range(B)]+[INF]\nfor q in range(Q):\n x=int(input())\n i=bisect.bisect_right(S,x)\n j=bisect.bisect_right(T,x)\n d=INF\n for s in [S[i-1],S[i]]:\n for t in [T[j-1],T[j]]:\n d1=abs(s-x)+abs(s-t)\n d2=abs(t-x)+abs(s-t)\n d=min(d,d1,d2)\n print(d)']
['Wrong Answer', 'Accepted']
['s515677474', 's671374252']
[14228.0, 12804.0]
[1839.0, 1714.0]
[440, 427]
p03112
u179169725
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['A, B, Q = list(map(int, input().split()))\n\nINF = 10 ** 18\n\nS = [-INF] + [int(input()) for _ in range(A)]+[INF]\nT = [-INF] + [int(input()) for _ in range(B)]+[INF]\n\nfrom bisect import bisect_right\nfrom itertools import product\n\nfor q in range(Q): \n x = int(input()) \n s_idx, t_idx = bisect_right(S, x), bisect_right(T, x)\n ans = INF\n \n for s, t in product(S[s_idx - 1:s_idx + 1], T[t_idx - 1:t_idx + 1]):\n t_root = abs(s - x) + abs(s - t) \n s_root = abs(s - x) + abs(s - t)\n ans = min(ans, t_root, s_root)\n \n print(ans)\n\n\n', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)']
['Wrong Answer', 'Accepted']
['s374467362', 's868090354']
[14844.0, 12800.0]
[1764.0, 1714.0]
[1641, 476]
p03112
u185354171
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_left(s, x), bisect.bisect_left(t, x)\n res = INF\n for S in [s[b + 1], s[b]]:\n for T in [t[d + 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)']
['Runtime Error', 'Accepted']
['s947453013', 's325697245']
[12284.0, 14592.0]
[1682.0, 1681.0]
[474, 476]
p03112
u185948224
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['from bisect import bisect_left\nA, B, Q = map(int, input().split())\ns = [int(input()) for _ in range(A)]\nt = [int(input()) for _ in range(B)]\n\ns.sort()\nt.sort()\n\nfor k in range(Q):\n x = int(input())\n ans = []\n ms = bisect_left(s, x)\n for i in [-1, 0]:\n if 0 <= ms + i <= A - 1:\n mt = bisect_left(t, s[ms + i])\n for j in [-1, 0]:\n if 0 <= mt + j <= B - 1:\n ans.append(abs(s[ms + i] - x) + abs(t[mt + j] - s[ms + i]))\n mt = bisect_left(t, x)\n for i in [-1, 0]:\n if 0 <= mt + i <= B - 1:\n ms = bisect_left(s, t[mt + i])\n for j in [-1, 0]:\n if 0 <= ms + j <= A - 1:\n ans.append(abs(t[mt + i] - x) + abs(s[ms + j] - t[mt + i]))\n print((ans))\n', 'from bisect import bisect_left\nA, B, Q = map(int, input().split())\ns = [int(input()) for _ in range(A)]\nt = [int(input()) for _ in range(B)]\n\ns.sort()\nt.sort()\n\nfor k in range(Q):\n x = int(input())\n ans = []\n ms = bisect_left(s, x)\n for i in [-1, 0]:\n if 0 <= ms + i <= A - 1:\n mt = bisect_left(t, s[ms + i])\n for j in [-1, 0]:\n if 0 <= mt + j <= B - 1:\n ans.append(abs(s[ms + i] - x) + abs(t[mt + j] - s[ms + i]))\n mt = bisect_left(t, x)\n for i in [-1, 0]:\n if 0 <= mt + i <= B - 1:\n ms = bisect_left(s, t[mt + i])\n for j in [-1, 0]:\n if 0 <= ms + j <= A - 1:\n ans.append(abs(t[mt + i] - x) + abs(s[ms + j] - t[mt + i]))\n print(min(ans))\n']
['Wrong Answer', 'Accepted']
['s598965597', 's058897563']
[19192.0, 17008.0]
[1641.0, 1500.0]
[783, 786]
p03112
u187205913
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
["a,b,q = map(int,input().split())\ns = [-float('inf')]+[int(input()) for i in range(a)]+[float('inf')]\nt = [-float('inf')]+[int(input()) for i in range(b)]+[float('inf')]\nx = [int(input()) for i in range(q)]\nimport bisect\nfor x_ in x:\n s_r = bisect.bisect_right(s,x_)\n t_r = bisect.bisect_right(s,x_)\n res = float('inf')\n for S in [s[s_r-1],s[s_r]]:\n for T in [t[t_r-1],t[t_r]]:\n d1 = abs(S-x_)+abs(T-S)\n d2 = abs(T-x_)+abs(S-T)\n res = min(res,d1,d2)\n print(res)", "a,b,q = map(int,input().split())\ns = [-float('inf')]+[int(input()) for i in range(a)]+[float('inf')]\nt = [-float('inf')]+[int(input()) for i in range(b)]+[float('inf')]\nx = [int(input()) for i in range(q)]\nimport bisect\nfor x_ in x:\n s_r = bisect.bisect_right(s,x_)\n t_r = bisect.bisect_right(s,x_)\n res = INF\n for S in [s[s_r-1],s[s_r]]:\n for T in [t[t_r-1],t[t_r]]:\n d1 = abs(S-x_)+abs(T-S)\n d2 = abs(T-x_)+abs(S-T)\n res = min(res,d1,d2)\n print(res)\n\nfor ans_ in ans:\n print(ans_)", "a,b,q = map(int,input().split())\ns = [int(input()) for i in range(a)]\nt = [int(input()) for i in range(b)]\nx = [int(input()) for i in range(q)]\nans = []\nfor x_ in x:\n s_ = []\n t_ = []\n for i in range(len(s)):\n s_.append(s[i]-x_)\n if s[i]-x_>0:\n break\n for i in range(len(t)):\n t_.append(t[i]-x_)\n if t_[i]-x_:\n break\n s_l=-float('inf')\n s_r=float('inf')\n t_l=-float('inf')\n t_r=float('inf')\n for k in s_:\n if k<0:\n s_l=k\n else:\n s_r=k\n break\n for k in t_:\n if k<0:\n t_l=k\n else:\n t_r=k\n break\n ans.append(min(max(abs(s_l),abs(t_l)),abs(s_l)*2+t_r,t_r*2+abs(s_l),max(s_r,t_r),s_r*2+abs(t_l),abs(t_l)*2+s_r))\nfor ans_ in ans:\n print(ans_)", "a,b,q = map(int,input().split())\ns = [-float('inf')]+[int(input()) for i in range(a)]+[float('inf')]\nt = [-float('inf')]+[int(input()) for i in range(b)]+[float('inf')]\nx = [int(input()) for i in range(q)]\nimport bisect\nfor x_ in x:\n s_r = bisect.bisect_right(s,x_)\n t_r = bisect.bisect_right(t,x_)\n res = float('inf')\n for S in [s[s_r-1],s[s_r]]:\n for T in [t[t_r-1],t[t_r]]:\n d1 = abs(S-x_)+abs(T-S)\n d2 = abs(T-x_)+abs(S-T)\n res = min(res,d1,d2)\n print(res)"]
['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s169091307', 's643673171', 's751823614', 's830801366']
[16128.0, 14964.0, 19948.0, 17532.0]
[1244.0, 487.0, 2105.0, 1249.0]
[515, 540, 816, 515]
p03112
u190405389
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\n\na,b,q = map(int,input().split())\ns = [-10**11] + [int(input()) for i in range(a)] + [10**11]\nt = [-10**11] + [int(input()) for i in range(b)] + [10**11]\n\n\n\nfor i in range(q):\n x = int(input())\n xs = bisect.bisect_right(s,x)\n xt = bisect.bisect_right(t,x)\n ss = [x-s[xs-1],s[xs]-x]\n tt = [x-t[xt-1],t[xt]-x]\n print(min(max(ss[0],tt[0]), max(ss[1],tt[1])))\n', 'import bisect\n\na,b,q = map(int,input().split())\ns = [-10**11] + [int(input()) for i in range(a)] + [10**11]\nt = [-10**11] + [int(input()) for i in range(b)] + [10**11]\n\n\n\nfor i in range(q):\n x = int(input())\n xs = bisect.bisect_right(s,x)\n xt = bisect.bisect_right(t,x)\n ss = [x-s[xs-1],s[xs]-x]\n tt = [x-t[xt-1],t[xt]-x]\n print(min(max(ss[0],tt[0]), max(ss[1],tt[1]), ss[0]*2+tt[1], ss[1]*2+tt[0], tt[0]*2+ss[1], tt[1]*2+ss[0]))\n']
['Wrong Answer', 'Accepted']
['s164444096', 's377761186']
[14740.0, 14608.0]
[1362.0, 1443.0]
[388, 448]
p03112
u190406011
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import sys\nimport bisect\n\n_input = sys.stdin.readlines()\nA, B, Q = [int(i) for i in _input[0].split()]\ndata = [int(i) for i in _input[1:]]\n"""\nA, B, Q = [int(i.strip()) for i in input().split()]\ndata = list()\nfor l in range(A+B+Q):\n data.append(int(input()))\n"""\ns_ls = sorted(data[:A] + [1e30,-1e30])\nt_ls = sorted(data[A:A+B] + [1e30,-1e30])\nx_ls = sorted(data[-Q:])\n\nfor x in x_ls:\n s_pos = bisect.bisect_left(s_ls, x)\n s_left = s_ls[s_pos-1]\n s_right = s_ls[s_pos]\n t_pos = bisect.bisect_left(t_ls, x)\n t_left = t_ls[t_pos-1]\n t_right = t_ls[t_pos]\n a = abs(x - min(s_left, t_left))\n b = abs(x- max(s_right, t_right))\n c = abs(x - max(s_left, t_left))\n d = abs(x - min(s_right, t_right))\n e = min(c,d)\n dis = min(a,\n b,\n c+d+e)\n', 'import sys\nimport bisect\n\nA, B, Q = [int(i.strip()) for i in input().split()]\ndata = list()\nfor l in range(A+B+Q):\n data.append(int(input()))\n\ns_ls = sorted(data[:A] + [1e30,-1e30])\nt_ls = sorted(data[A:A+B] + [1e30,-1e30])\nx_ls = data[-Q:]\n \nfor x in x_ls:\n s_pos = bisect.bisect_left(s_ls, x)\n s_left = s_ls[s_pos-1]\n s_right = s_ls[s_pos]\n t_pos = bisect.bisect_left(t_ls, x)\n t_left = t_ls[t_pos-1]\n t_right = t_ls[t_pos]\n a = abs(x - min(s_left, t_left))\n b = abs(x- max(s_right, t_right))\n c = abs(x - max(s_left, t_left))\n d = abs(x - min(s_right, t_right))\n e = min(c,d)\n dis = min(a,\n b,\n c+d+e)', 'import sys\nimport bisect\n\nA, B, Q = [int(i.strip()) for i in input().split()]\ndata = list()\nfor l in range(A+B+Q):\n data.append(int(input()))\n\ns_ls = sorted(data[:A] + [1e30,-1e30])\nt_ls = sorted(data[A:A+B] + [1e30,-1e30])\nx_ls = sorted(data[-Q:])\n \nfor x in x_ls:\n s_pos = bisect.bisect_left(s_ls, x)\n s_left = s_ls[s_pos-1]\n s_right = s_ls[s_pos]\n t_pos = bisect.bisect_left(t_ls, x)\n t_left = t_ls[t_pos-1]\n t_right = t_ls[t_pos]\n a = abs(x - min(s_left, t_left))\n b = abs(x- max(s_right, t_right))\n c = abs(x - max(s_left, t_left))\n d = abs(x - min(s_right, t_right))\n e = min(c,d)\n dis = min(a,\n b,\n c+d+e)', 'import sys\nimport bisect\n \n_input = sys.stdin.readlines()\nA, B, Q = [int(i) for i in _input[0].split()]\ndata = [int(i) for i in _input[1:]]\n"""\nA, B, Q = [int(i.strip()) for i in input().split()]\ndata = list()\nfor l in range(A+B+Q):\n data.append(int(input()))\n"""\ns_ls = sorted(data[:A] + [1e30,-1e30])\nt_ls = sorted(data[A:A+B] + [1e30,-1e30])\nx_ls = data[-Q:]\n \nfor x in x_ls:\n s_pos = bisect.bisect_left(s_ls, x)\n s_left = s_ls[s_pos-1]\n s_right = s_ls[s_pos]\n t_pos = bisect.bisect_left(t_ls, x)\n t_left = t_ls[t_pos-1]\n t_right = t_ls[t_pos]\n a = abs(x - min(s_left, t_left))\n b = abs(x- max(s_right, t_right))\n c = abs(x - max(s_left, t_left))\n d = abs(x - min(s_right, t_right))\n e = min(c,d)\n dis = min(a,\n b,\n c+d+e)', 'import sys\nimport bisect\n\n_input = sys.stdin.readlines()\nA, B, Q = [int(i) for i in _input[0].split()]\ndata = [int(i) for i in _input[1:]]\n"""\nA, B, Q = [int(i.strip()) for i in input().split()]\ndata = list()\nfor l in range(A+B+Q):\n data.append(int(input()))\n"""\ns_ls = sorted(data[:A] + [1e30,-1e30])\nt_ls = sorted(data[A:A+B] + [1e30,-1e30])\nx_ls = data[-Q:]\n\nfor x in x_ls:\n s_pos = bisect.bisect_left(s_ls, x)\n s_left = s_ls[s_pos-1]\n s_right = s_ls[s_pos]\n t_pos = bisect.bisect_left(t_ls, x)\n t_left = t_ls[t_pos-1]\n t_right = t_ls[t_pos]\n a = abs(x - min(s_left, t_left))\n b = abs(x- max(s_right, t_right))\n c = abs(x - s_left) + abs(x - t_right) + min(abs(x - s_left), abs(x - t_right))\n d = abs(x - t_left) + abs(x - s_right) + min(abs(x - t_left), abs(x - s_right))\n dis = min(a,\n b,\n c,\n d)\n print(dis)']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s108830665', 's482719336', 's721196757', 's998122164', 's348015476']
[42296.0, 18048.0, 18424.0, 39428.0, 42380.0]
[518.0, 906.0, 902.0, 518.0, 702.0]
[797, 789, 797, 790, 891]
p03112
u200785298
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['#!/usr/bin/env python3\nimport sys\n \n \ndef solve(n: int, m: int, Q: int, s: "List[int]", t: "List[int]", x: "List[int]"):\n \n def check_pos(target, a, x):\n ret = {}\n a_x = a + x\n a_x.sort()\n idx = 0\n while idx < len(a_x) and a_x[idx] < target[0]:\n dis = target[0] - a_x[idx]\n ret[a_x[idx]] = [dis, [target[0], dis]] \n idx += 1\n for i in range(len(target) - 1):\n while idx < len(a_x) and target[i] <= a_x[idx] <= target[i + 1]:\n pos = a_x[idx]\n l = a_x[idx] - target[i]\n r = target[i + 1] - a_x[idx]\n ret[pos] = [\n min(l, r),\n [target[i], l],\n [target[i + 1], r]\n ]\n idx += 1\n while idx < len(a_x):\n dis = a_x[idx] - target[-1]\n ret[a_x[idx]] = [dis, [target[-1], dis]] \n idx += 1\n return ret\n \n nearest_s = check_pos(s, t, x)\n nearest_t = check_pos(t, s, x)\n return\n \n for q in x:\n ret = min(\n min([(pos_dis[1] + nearest_t[pos_dis[0]][0]) for pos_dis in nearest_s[q][1:]]),\n min([(pos_dis[1] + nearest_s[pos_dis[0]][0]) for pos_dis in nearest_t[q][1:]]))\n print(ret)\n return\n \n \ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n A = int(next(tokens)) # type: int\n B = int(next(tokens)) # type: int\n Q = int(next(tokens)) # type: int\n s = [ int(next(tokens)) for _ in range(A) ] # type: "List[int]"\n t = [ int(next(tokens)) for _ in range(B) ] # type: "List[int]"\n x = [ int(next(tokens)) for _ in range(Q) ] # type: "List[int]"\n solve(A, B, Q, s, t, x)\n \nif __name__ == \'__main__\':\n main()', '#!/usr/bin/env python3\nimport sys\n\n\ndef solve(n: int, m: int, Q: int, s: "List[int]", t: "List[int]", x: "List[int]"):\n\n def check_pos(target, a, x):\n ret = {}\n a_x = a + x\n a_x.sort()\n idx = 0\n while idx < len(a_x) and a_x[idx] < target[0]:\n pos = a_x[idx]\n ret[pos] = {\n \'dis\': target[0] - a_x[idx],\n \'pos\': [target[0]]\n }\n idx += 1\n for i in range(len(target) - 1):\n while idx < len(a_x) and target[i] <= a_x[idx] <= target[i + 1]:\n pos = a_x[idx]\n ret[pos] = {\'dis\': min(a_x[idx] - target[i], target[i + 1] - a_x[idx])}\n if a_x[idx] - target[i] == target[i + 1] - a_x[idx]:\n ret[pos][\'pos\'] = [target[i], target[i + 1]]\n elif a_x[idx] - target[i] < target[i + 1] - a_x[idx]:\n ret[pos][\'pos\'] = [target[i]]\n else:\n ret[pos][\'pos\'] = [target[i + 1]]\n idx += 1\n while idx < len(a_x):\n pos = a_x[idx]\n ret[pos] = {\n \'dis\': a_x[idx] - target[-1],\n \'pos\': [target[-1]]\n }\n idx += 1\n return ret\n\n nearest_s = check_pos(s, t, x)\n nearest_t = check_pos(t, s, x)\n\n print(\'hoge\')\n return\n\n for q in x:\n ret = min(nearest_s[q][\'dis\'] + min([nearest_t[pos][\'dis\'] for pos in nearest_s[q][\'pos\']]),\n nearest_t[q][\'dis\'] + min([nearest_s[pos][\'dis\'] for pos in nearest_t[q][\'pos\']]))\n print(ret)\n return\n\n\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n A = int(next(tokens)) # type: int\n B = int(next(tokens)) # type: int\n Q = int(next(tokens)) # type: int\n s = [ int(next(tokens)) for _ in range(A) ] # type: "List[int]"\n t = [ int(next(tokens)) for _ in range(B) ] # type: "List[int]"\n x = [ int(next(tokens)) for _ in range(Q) ] # type: "List[int]"\n solve(A, B, Q, s, t, x)\n\nif __name__ == \'__main__\':\n main()\n', '#!/usr/bin/env python3\nimport sys\n\n\ndef solve(N: int, M: int, Q: int, s: "List[int]", t: "List[int]", x: "List[int]"):\n\n def binary_search(ary, val):\n n = len(ary)\n l = -1\n r = n\n while r - l > 1:\n mid = (l + r) // 2\n if ary[mid] >= val:\n r = mid\n else:\n l = mid\n if l == -1:\n return [ary[0]]\n if r == n:\n return [ary[n - 1]]\n return [ary[l], ary[r]]\n\n for q in x:\n ret = float(\'inf\')\n a_pos = binary_search(s, q)\n b_pos = binary_search(t, q)\n for a in a_pos:\n for b in b_pos:\n ret = min(ret, abs(a - q) + abs(b - a))\n ret = min(ret, abs(b - q) + abs(a - b))\n print(ret)\n return\n\n\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n A = int(next(tokens)) # type: int\n B = int(next(tokens)) # type: int\n Q = int(next(tokens)) # type: int\n s = [ int(next(tokens)) for _ in range(A) ] # type: "List[int]"\n t = [ int(next(tokens)) for _ in range(B) ] # type: "List[int]"\n x = [ int(next(tokens)) for _ in range(Q) ] # type: "List[int]"\n solve(A, B, Q, s, t, x)\n\nif __name__ == \'__main__\':\n main()\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s911751660', 's969643029', 's791846444']
[183928.0, 210792.0, 16160.0]
[1762.0, 1799.0, 1394.0]
[1902, 2164, 1355]
p03112
u203843959
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\n\nA,B,Q=map(int,input().split())\nslist = []\nfor i in range(A):\n slist.append(int(input()))\n#print(slist)\n \ntlist = []\nfor i in range(B):\n tlist.append(int(input()))\n#print(tlist)\n\nfor i in range(Q):\n x = int(input())\n min_dist = 10**11\n \n # x->s->t\n if x < slist[0]:\n si = [0]\n elif slist[-1] < x:\n si = [len(slist)-1]\n else:\n\tsl = bisect.bisect(slist,x) \n si = [sl-1,sl]\n \n for index in si:\n s = slist[index]\n dist = abs(x-s)\n\n tl = bisect.bisect(tlist,s)\n if tl == 0:\n dist += abs(s-tlist[0])\n elif tl == len(tlist):\n dist += abs(s-tlist[len(tlist)-1])\n else:\n dist += min(abs(s-tlist[tl-1]),abs(s-tlist[tl]))\n \n if dist < min_dist:\n min_dist = dist\n\n # x->t->s\n if x < tlist[0]:\n ti = [0]\n elif tlist[-1] < x:\n ti = [len(tlist)-1]\n else:\n\ttl = bisect.bisect(tlist,x) \n ti = [tl-1,tl]\n\n tl = bisect.bisect(tlist,x)\n if tl == 0:\n ti = [0]\n elif tl == len(tlist):\n ti = [tl-1]\n else:\n ti = [tl-1,tl]\n \n for index in ti:\n t = tlist[index]\n dist = abs(x-t)\n\n sl = bisect.bisect(slist,t)\n if sl == 0:\n dist += abs(t-slist[0])\n elif sl == len(slist):\n dist += abs(t-slist[len(slist)-1])\n else:\n dist += min(abs(t-slist[sl-1]),abs(t-slist[sl]))\n \n if dist < min_dist:\n min_dist = dist\n\n print(min_dist)\n', 'import bisect\n\nA,B,Q=map(int,input().split())\nslist = []\nfor i in range(A):\n slist.append(int(input()))\n#print(slist)\n \ntlist = []\nfor i in range(B):\n tlist.append(int(input()))\n#print(tlist)\n\nfor i in range(Q):\n x = int(input())\n min_dist = 10**11\n \n # x->s->t\n if x < slist[0]:\n si = [0]\n elif slist[-1] < x:\n si = [len(slist)-1]\n else:\n\tsl = bisect.bisect(slist,x) \n si = [sl-1,sl]\n \n for index in si:\n s = slist[index]\n dist = abs(x-s)\n\n tl = bisect.bisect(tlist,s)\n if tl == 0:\n dist += abs(s-tlist[0])\n elif tl == len(tlist):\n dist += abs(s-tlist[len(tlist)-1])\n else:\n dist += min(abs(s-tlist[tl-1]),abs(s-tlist[tl]))\n \n if dist < min_dist:\n min_dist = dist\n\n # x->t->s\n if x < tlist[0]:\n ti = [0]\n elif tlist[-1] < x:\n ti = [len(tlist)-1]\n else:\n\ttl = bisect.bisect(tlist,x) \n ti = [tl-1,tl]\n\n for index in ti:\n t = tlist[index]\n dist = abs(x-t)\n\n sl = bisect.bisect(slist,t)\n if sl == 0:\n dist += abs(t-slist[0])\n elif sl == len(slist):\n dist += abs(t-slist[len(slist)-1])\n else:\n dist += min(abs(t-slist[sl-1]),abs(t-slist[sl]))\n \n if dist < min_dist:\n min_dist = dist\n\n print(min_dist)\n', 'import bisect\n\nA,B,Q=map(int,input().split())\nslist = []\nfor i in range(A):\n slist.append(int(input()))\n#print(slist)\n\ntlist = []\nfor i in range(B):\n tlist.append(int(input()))\n#print(tlist)\n\nfor i in range(Q):\n x = int(input())\n min_dist = 10**11\n \n # x->s->t\n if x < slist[0]:\n si = [0]\n elif slist[-1] < x:\n si = [len(slist)-1]\n else:\n sl = bisect.bisect(slist,x)\n si = [sl-1,sl]\n \n for index in si:\n s = slist[index]\n dist = abs(x-s)\n\n if s < tlist[0]:\n dist += tlist[0]-s\n elif tlist[-1] < s:\n dist += s-tlist[-1]\n else:\n tl = bisect.bisect(tlist,s) \n dist += min(s-tlist[tl-1],tlist[tl]-s)\n \n if dist < min_dist:\n min_dist = dist\n\n # x->t->s\n if x < tlist[0]:\n ti = [0]\n elif tlist[-1] < x:\n ti = [len(tlist)-1]\n else:\n tl = bisect.bisect(tlist,x)\n ti = [tl-1,tl]\n \n for index in ti:\n t = tlist[index]\n dist = abs(x-t)\n\n if t < slist[0]:\n dist += slist[0]-t\n elif slist[-1] < t:\n dist += t-slist[-1]\n else:\n sl = bisect.bisect(slist,t)\n dist += min(t-slist[sl-1],slist[sl]-t)\n \n if dist < min_dist:\n min_dist = dist\n\n print(min_dist)\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s016407659', 's637204310', 's410036250']
[3060.0, 3060.0, 12080.0]
[17.0, 17.0, 1991.0]
[1355, 1227, 1179]
p03112
u210543511
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['improt bisect\nA, B, Q = map(int, input().split())\nss = [int(input()) for i in range(A)]\nts = [int(input()) for i in range(B)]\nxs = [int(input()) for i in range(Q)]\nINF = 10**11\n\n-INF, INF = -1, 10**10 + 1\nss = [-INF] + ss + [INF]\nts = [-INF] + ts + [INF]\n\n# s_e is index the nearest s on the east side of x\nfor x in xs:\n s_e_ix = bisect.bisect_left(ss, x)\n s_e = ss[s_e_ix]\n s_w = ss[s_e_ix - 1]\n t_e_ix = bisect.bisect_left(ts, x)\n t_e = ts[t_e_ix]\n t_w_ix = ts[t_e_ix - 1]\n \n d = INF\n for s in [s_w, s_e]:\n for t in [t_w, t_e]:\n d0 = abs(s-x) + abs(t-s)\n d1 = abs(t-x) + abs(s-t)\n d = min(d0, d1, d)\n print(d)\n \n ', 'import bisect\nA, B, Q = map(int, input().split())\nss = [int(input()) for i in range(A)]\nts = [int(input()) for i in range(B)]\nxs = [int(input()) for i in range(Q)]\nINF = 10**11\n \n-INF, INF = -1, 10**10 + 1\nss = [-INF] + ss + [INF]\nts = [-INF] + ts + [INF]\n \n# s_e is index the nearest s on the east side of x\nfor x in xs:\n s_e_ix = bisect.bisect_left(ss, x)\n s_e = ss[s_e_ix]\n s_w = ss[s_e_ix - 1]\n t_e_ix = bisect.bisect_left(ts, x)\n t_e = ts[t_e_ix]\n t_w_ix = ts[t_e_ix - 1]\n \n d = INF\n for s in [s_w, s_e]:\n for t in [t_w, t_e]:\n d0 = abs(s-x) + abs(t-s)\n d1 = abs(t-x) + abs(s-t)\n d = min(d0, d1, d)\n print(d)', 'import bisect\nA, B, Q = map(int, input().split())\nss = [int(input()) for i in range(A)]\nts = [int(input()) for i in range(B)]\nxs = [int(input()) for i in range(Q)]\nINF = 10**11\n\nss = [-INF] + ss + [INF]\nts = [-INF] + ts + [INF]\n \n# s_e is index the nearest s on the east side of x\nfor x in xs:\n s_e_ix = bisect.bisect_left(ss, x)\n s_e = ss[s_e_ix]\n s_w = ss[s_e_ix - 1]\n \n t_e_ix = bisect.bisect_left(ts, x)\n t_e = ts[t_e_ix]\n t_w = ts[t_e_ix - 1]\n \n d = INF\n for s in [s_w, s_e]:\n for t in [t_w, t_e]:\n d0 = abs(s-x) + abs(t-s)\n d1 = abs(t-x) + abs(s-t)\n d = min(d0, d1, d)\n print(d)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s259273171', 's306705912', 's911061861']
[2940.0, 3064.0, 16780.0]
[18.0, 17.0, 1211.0]
[672, 641, 613]
p03112
u219015402
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\n\nA, B, Q = map(int,input().split())\nINF = 10**18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nx_list = [int(input()) for i in range(Q)]\n\nfor x in x_list:\n \n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n a = b - 1\n c = d - 1 \n ans = min(abs(s[a]-x) + min(abs(t[a]-s[a]), abs(t[b]-s[a])),\n abs(s[b]-x) + min(abs(t[a]-s[b]), abs(t[b]-s[b])),\n abs(t[a]-x) + min(abs(s[a]-t[a]), abs(s[b]-t[a])),\n abs(t[b]-x) + min(abs(s[a]-t[b]), abs(s[b]-t[b])))\n\n # for s in [s_list[a], s_list[b]]:\n # for t in [t_list[c], t_list[d]]:\n # dist1 = abs(s-x) + abs(t-s)\n # dist2 = abs(t-x) + abs(t-s)\n # ans = min(ans, dist1,dist2)\n print(ans)\n', 'import bisect\n\nA, B, Q = map(int,input().split())\ns_list = [-inf] + [int(input()) for i in range(A)] + [inf]\nt_list = [-inf] + [int(input()) for i in range(B)] + [inf]\nx_list = [int(input()) for i in range(Q)]\n\nfor x in x_list:\n \n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n a = b - 1\n c = d - 1 \n ans = inf\n for s in s_list[a], s_list[b]:\n for t in t_list[c], t_list[d]:\n dist1 = abs(s-x) + abs(t-s)\n dist2 = abs(t-x) + abs(t-s)\n ans = min(ans, dist1,dist2)\n print(ans)\n', 'import numpy as np\nA, B, Q = map(int,input().split())\ns_list = [int(input()) for i in range(A)]\nt_list = [int(input()) for i in range(B)]\nx_list = [int(input()) for i in range(Q)]\n\n\ndef get_dist_to_first_cp(x,li):\n dist1 = np.array(li) -x \n abs_dist1 = abs(dist1)\n dist_to_first_cp = min(abs_dist1)\n first_cp_num = np.argmin(abs_dist1)\n first_cp_pos = x + dist1[first_cp_num]\n return dist_to_first_cp, first_cp_pos\n \n\n\nu_list = s_list + t_list\nfor i, x in enumerate(x_list):\n # shrine first\n dist_to_first_cp, first_cp_pos = get_dist_to_first_cp(x,s_list)\n dist2 = abs(np.array(t_list) - dist_to_first_cp)\n dist_to_sec_cp = min(dist2)\n ans_s = dist_to_first_cp + dist_to_sec_cp\n # temple first\n dist_to_first_cp, first_cp_pos = get_dist_to_first_cp(x,t_list)\n dist2 = abs(np.array(s_list) - dist_to_first_cp)\n dist_to_sec_cp = min(dist2)\n\n ans_t = dist_to_first_cp + dist_to_sec_cp\n\n print(min(ans_s,ans_t))\n', 'import numpy as np\nA, B, Q = map(int,input().split())\ns_list = np.array([int(input()) for i in range(A)])\nt_list = np.array([int(input()) for i in range(B)])\nx_list = [int(input()) for i in range(Q)]\n\ndef get_dist_to_first_cp(x,li):\n dist1 = li -x\n abs_dist1 = list(map(abs,dist1))\n dist_to_first_cp = min(abs_dist1)\n first_cp_num = np.argmin(abs_dist1)\n first_cp_pos = x + dist1[first_cp_num]\n return dist_to_first_cp, first_cp_pos\n \n\n\nu_list = s_list + t_list\nfor i, x in enumerate(x_list):\n # shrine first\n dist_to_first_cp, first_cp_pos = get_dist_to_first_cp(x,s_list)\n dist2 = abs(np.array(t_list) - first_cp_pos)\n dist_to_sec_cp = min(dist2)\n ans_s = dist_to_first_cp + dist_to_sec_cp\n # temple first\n dist_to_first_cp, first_cp_pos = get_dist_to_first_cp(x,t_list)\n dist2 = abs(np.array(s_list) - first_cp_pos)\n dist_to_sec_cp = min(dist2)\n \n ans_t = dist_to_first_cp + dist_to_sec_cp\n\n print(min(ans_s,ans_t))\n', 'import numpy as np\nA, B, Q = map(int,input().split())\ns_list = np.array([int(input()) for i in range(A)])\nt_list = np.array([int(input()) for i in range(B)])\nx_list = [int(input()) for i in range(Q)]\n\ndef get_dist_to_first_cp(x,li):\n dist1 = li -x\n abs_dist1 = abs(dist1)\n dist_to_first_cp = min(abs_dist1)\n first_cp_num = np.argmin(abs_dist1)\n first_cp_pos = x + dist1[first_cp_num]\n return dist_to_first_cp, first_cp_pos\n \n\n\nu_list = s_list + t_list\nfor i, x in enumerate(x_list):\n # shrine first\n dist_to_first_cp, first_cp_pos = get_dist_to_first_cp(x,s_list)\n dist2 = abs(np.array(t_list) - first_cp_pos)\n dist_to_sec_cp = min(dist2)\n ans_s = dist_to_first_cp + dist_to_sec_cp\n # temple first\n dist_to_first_cp, first_cp_pos = get_dist_to_first_cp(x,t_list)\n dist2 = abs(np.array(s_list) - first_cp_pos)\n dist_to_sec_cp = min(dist2)\n \n ans_t = dist_to_first_cp + dist_to_sec_cp\n\n print(min(ans_s,ans_t))\n', 'import bisect\n\nA, B, Q = map(int,input().split())\nINF = 10**18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nx_list = [int(input()) for i in range(Q)]\n\nfor x in x_list:\n \n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n a = b - 1\n c = d - 1 \n ans = min(abs(s[a]-x) + min(abs(t[c]-s[a]), abs(t[d]-s[a])),\n abs(s[b]-x) + min(abs(t[c]-s[b]), abs(t[d]-s[b])),\n abs(t[c]-x) + min(abs(s[a]-t[c]), abs(s[b]-t[c])),\n abs(t[d]-x) + min(abs(s[a]-t[d]), abs(s[b]-t[d])))\n\n # for s in [s_list[a], s_list[b]]:\n # for t in [t_list[c], t_list[d]]:\n # dist1 = abs(s-x) + abs(t-s)\n # dist2 = abs(t-x) + abs(t-s)\n # ans = min(ans, dist1,dist2)\n print(ans)\n']
['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s025276517', 's059816867', 's106876199', 's213794681', 's696006809', 's227519515']
[16144.0, 3064.0, 27836.0, 25884.0, 20736.0, 16144.0]
[1028.0, 18.0, 2109.0, 2109.0, 2109.0, 1040.0]
[814, 550, 962, 976, 966, 814]
p03112
u223646582
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
["import bisect\nA, B, Q = map(int, input().split())\nS = [int(input()) for _ in range(A)]\nT = [int(input()) for _ in range(B)]\nX = [int(input()) for _ in range(Q)]\n\nA = []\nfor x in X:\n SL, SR, TL, TR = 10**20, 10**20, 10**20, 10**20\n i = bisect.bisect_left(S, x)\n if i != 0:\n SL = x-S[i-1]\n if i != A:\n SR = S[i]-x\n\n j = bisect.bisect_left(T, x)\n if j != 0:\n TL = x-T[j-1]\n if j != B:\n TR = T[j]-x\n\n ans = min(max(SL, TL), min(2*SL+TR, SL+2*TR),\n min(2*TL+SR, TL+2*SR), max(SR, TR))\n A.append(ans)\nprint(*A, sep='\\n')\n", 'import bisect\nA, B, Q = map(int, input().split())\nS = [int(input()) for _ in range(A)]\nT = [int(input()) for _ in range(B)]\nX = [int(input()) for _ in range(Q)]\n\nfor x in X:\n SL, SR, TL, TR = 10**20, 10**20, 10**20, 10**20\n i = bisect.bisect_left(S, x)\n if i != 0:\n SL = x-S[i-1]\n if i != A:\n SR = S[i]-x\n\n j = bisect.bisect_left(T, x)\n if j != 0:\n TL = x-T[j-1]\n if j != B:\n TR = T[j]-x\n\n ans = min(max(SL, TL), min(2*SL+TR, SL+2*TR),\n min(2*TL+SR, TL+2*SR), max(SR, TR))\n print(ans)\n']
['Runtime Error', 'Accepted']
['s245733143', 's077903402']
[21328.0, 16144.0]
[942.0, 931.0]
[583, 553]
p03112
u223904637
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\na,b,q=map(int,input().split())\ns=[]\nt=[]\nfor i in range(a):\n s.append(int(input()))\nfor i in range(b):\n t.append(int(input()))\nfor i in range(q):\n x=int(input())\n si=bisect.bisect_left(s,x)\n ti=bisect.bisect_left(t,x)\n if si==a:\n sk=[s[a-1]]\n elif si==0:\n sk=[s[0]]\n else:\n sk=[s[si-1],s[si]]\n if ti==0:\n tk=[t[0]]\n else:\n tk=[t[ti-1],t[ti]]\n ans=1000000000000\n for f in sk:\n for g in tk:\n ans=min(ans,abs(x-f)+abs(f-g),abs(x-g)+abs(g-f))\nprint(ans)', 'import bisect\na,b,q=map(int,input().split())\ns=[]\nt=[]\nfor i in range(a):\n s.append(int(input()))\nfor i in range(b):\n t.append(int(input()))\nfor i in range(q):\n x=int(input())\n si=bisect.bisect_left(s,x)\n ti=bisect.bisect_left(t,x)\n if si==a:\n sk=[s[a-1]]\n elif si==0:\n sk=[s[0]]\n else:\n sk=[s[si-1],s[si]]\n if ti==0:\n tk=[t[0]]\n elif ti==b:\n tk=[t[b-1]]\n else:\n tk=[t[ti-1],t[ti]]\n ans=1000000000000\n for f in sk:\n for g in tk:\n ans=min(ans,abs(x-f)+abs(f-g),abs(x-g)+abs(g-f))\n print(ans)\n']
['Runtime Error', 'Accepted']
['s509345672', 's629766110']
[11068.0, 12092.0]
[1116.0, 1709.0]
[552, 593]
p03112
u227082700
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['from bisect import bisect_left,bisect_right\na,b,q=map(int,input().split())\ns=[-(10**21)]+[int(input())for _ in range(a)]+[10**21]\nt=[-(10**21)]+[int(input())for _ in range(b)]+[10**21]\nfor _ in range(q):\n x=int(input())\n s1,s2=s[bisect_right(s,x)-1],s[bisect_right(s,x)]\n t1,t2=t[bisect_right(t,x)-1],t[bisect_right(t,x)]\n ans=10**11\n for i in [s1,s2]:\n for j in [t1,t2]:\n ans=min(ans,abs(i-j)+min(abs(x-i),abs(x-j)))\nprint(ans)', 'a,b,q=map(int,input().split())\ns=[-10**30]+[int(input())for _ in range(a)]+[10**30]\nt=[-10**30]+[int(input())for _ in range(b)]+[10**30]\nx=[int(input())for _ in range(q)]\nfrom bisect import bisect_left,bisect_right\nfor xx in x:\n s1=s[bisect_right(s,xx)-1]\n s2=s[bisect_right(s,xx)]\n t1=t[bisect_right(t,xx)-1]\n t2=t[bisect_right(t,xx)]\n ans=[]\n ans.append(abs(s1-t1)+min(abs(xx-s1),abs(xx-t1)))\n ans.append(abs(s1-t2)+min(abs(xx-s1),abs(xx-t2)))\n ans.append(abs(s2-t1)+min(abs(xx-s2),abs(xx-t1)))\n ans.append(abs(s2-t2)+min(abs(xx-s2),abs(xx-t2)))\n print(min(ans))']
['Wrong Answer', 'Accepted']
['s372188296', 's063184497']
[11672.0, 16132.0]
[1236.0, 1117.0]
[441, 574]
p03112
u227170240
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['A, B, Q = map(int, input().split())\ns = [0] + [int(input()) for i in range(A)] + [10**11]\nt = [0] + [int(input()) for i in range(B)] + [10**11]\n\ndef nibutans(x, l, r):\n\tif r - l <= 1:\n\t\treturn r\n\tnibu = (s[r] + s[l]) // 2\n\treturn nibutans(x, nibu, r) if x > nibu else nibutans(x, l, nibu)\n\ndef nibutant(x, l, r):\n\tif l == r and x >= l:\n\t\treturn l + 1\n\tif r - l <= 1:\n\t\treturn r\n\tnibu = (t[r] + t[l]) // 2\n\treturn nibutant(x, nibu, r) if x > nibu else nibutant(x, l, nibu)\n\nfor i in range(Q):\n\tx = int(input())\n\tsr, tr = nibutans(x, 0, -1), nibutant(x, 0, -1)\n\tans = 10**11\n\tfor S in [s[sr - 1], s[sr]]:\n\t\tfor T in [t[tr - 1], t[tr]]:\n\t\t\td1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n\t\t\tans = min(ans, d1, d2)\n\tprint(ans)\n', "A, B, Q = map(int, input().split())\ns = [-10**11] + [int(input()) for i in range(A)] + [10**11]\nt = [-10**11] + [int(input()) for i in range(B)] + [10**11]\ndef nibutans(x, l, r):\n\tif r - l <= 1:\n\t\treturn r\n\tnibu = (r + l) // 2\n\treturn nibutans(x, nibu, r) if x > s[nibu] else nibutans(x, l, nibu)\ndef nibutant(x, l, r):\n\tif r - l <= 1:\n\t\treturn r\n\tnibu = (r + l) // 2\n\treturn nibutant(x, nibu, r) if x > t[nibu] else nibutant(x, l, nibu)\nfor i in range(Q):\n\tx = int(input())\n\tsr, tr = nibutans(x, 0, A + 1), nibutant(x, 0, B + 1)\n\tans = 10**17\n\tfor S in [s[sr - 1], s[sr]]:\n\t\tfor T in [t[tr - 1], t[tr]]:\n\t\t\td1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n\t\t\tprint(str(ans) + ' ' + str(d1) + ' ' + str(d2))\n\t\t\tans = min(ans, d1, d2)\n\tprint(ans)", 'import bisect\nA, B, Q = map(int, input().split())\ns = [-10**11] + [int(input()) for i in range(A)] + [10**11]\nt = [-10**11] + [int(input()) for i in range(B)] + [10**11]\n\n\nfor q in range(Q):\n\tx = int(input())\n\tb, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n\tres = 10**13\n\tfor S in [s[b - 1], s[b]]:\n\t\tfor T in [t[d - 1], t[d]]:\n\t\t\td1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n\t\t\tres = min(res, d1, d2)\n\tprint(res)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s071595774', 's115530453', 's115511097']
[12800.0, 21120.0, 12816.0]
[1549.0, 2104.0, 1707.0]
[733, 754, 1064]
p03112
u232852711
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\ninf = 10**18\na, b, q = map(int, input().split())\ns = [-inf] + [int(input()) for _ in range(a)] + [inf]\nt = [-inf] + [int(input()) for _ in range(a)] + [inf]\n\nfor _ in range(q):\n x = int(input())\n i = bisect.bisect_right(s, x)\n j = bisect.bisect_right(t, x)\n ans = inf\n for s_x in [s[i-1], s[i]]:\n for t_x in [t[i-1], t[i]]:\n ans0 = abs(s_x - x) + abs(t_x - s_x)\n ans1 = abs(t_x - x) + abs(s_x - t_x)\n ans = min(ans, ans0, ans1)\n print(ans)\n', 'import bisect\ninf = 10**18\na, b, q = map(int, input().split())\ns = [-inf] + [int(input()) for _ in range(a)] + [inf]\nt = [-inf] + [int(input()) for _ in range(a)] + [inf]\n\nfor _ in range(q):\n x = int(input())\n i = bisect.bisect_right(s, x)\n j = bisect.bisect_right(t, x)\n ans = inf\n for s_x in [s[i-1], s[i]]:\n for t_x in [t[j-1], t[j]]:\n ans0 = abs(s_x - x) + abs(t_x - s_x)\n ans1 = abs(t_x - x) + abs(s_x - t_x)\n ans = min(ans, ans0, ans1)\n print(ans)', 'import bisect\ninf = 10**18\na, b, q = map(int, input().split())\ns = [-inf] + [int(input()) for _ in range(a)] + [inf]\nt = [-inf] + [int(input()) for _ in range(b)] + [inf]\n\nfor _ in range(q):\n x = int(input())\n i = bisect.bisect_right(s, x)\n j = bisect.bisect_right(t, x)\n ans = inf\n for s_x in [s[i-1], s[i]]:\n for t_x in [t[j-1], t[j]]:\n ans0 = abs(s_x - x) + abs(t_x - s_x)\n ans1 = abs(t_x - x) + abs(s_x - t_x)\n ans = min(ans, ans0, ans1)\n print(ans)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s710388004', 's858405175', 's898257396']
[14604.0, 14336.0, 14228.0]
[1762.0, 1750.0, 1768.0]
[512, 511, 511]
p03112
u268793453
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['\na, b, q = [int(i) for i in input().split()]\nS = [int(input()) for i in range(a)]\nT = [int(input()) for i in range(b)]\nX = [int(input()) for i in range(q)]\nprint(0)', 'from bisect import bisect_left as bisect\n\na, b, q = [int(i) for i in input().split()]\nS = [int(input()) for i in range(a)]\nT = [int(input()) for i in range(b)]\nX = [int(input()) for i in range(q)]\n\nfor x in X:\n s_i = bisect(S, x)\n t_i = bisect(T, x)\n min_s = min(abs(x - S[max(0, s_i - 1)]), abs(x - S[min(a - 1, s_i)]))\n min_t = min(abs(x - T[max(0, t_i - 1)]), abs(x - T[min(b - 1, t_i)]))\n ans = min_s + min_t + min(min_s, min_t)\n if s_i > 0 and t_i > 0:\n ans = min(ans, abs(x - min(S[s_i - 1], T[t_i - 1])))\n if s_i < a and t_i < b:\n ans = min(ans, abs(x - max(S[s_i], T[t_i])))\n \n print(ans)']
['Wrong Answer', 'Accepted']
['s738368925', 's595553225']
[15012.0, 16156.0]
[481.0, 1109.0]
[202, 637]
p03112
u275934251
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['from bisect import bisect_left\na,b,q=map(int,input().split())\ns=[]\nt=[]\nx=[]\ns.append(-float("inf"))\nt.append(-float("inf"))\nfor i in range(a):\n s.append(int(input()))\nfor i in range(b):\n t.append(int(input()))\ns.append(float("inf"))\nt.append(float("inf"))\ns.sort()\nt.sort()\nfor i in range(q):\n x=int(input())\n ans=float("inf")\n tmp_s_1=bisect.bisect_left(s,x)-1\n tmp_s_2=tmp_s_1+1\n tmp_s_1_t=bisect.bisect_left(t,s[tmp_s_1])\n tmp_s_2_t=bisect.bisect_left(t,s[tmp_s_2])\n ans=min(abs(x-s[tmp_s_1])+abs(s[tmp_s_1]-t[tmp_s_1_t-1]), abs(x-s[tmp_s_1])+abs(s[tmp_s_1]-t[tmp_s_1_t]), abs(x-s[tmp_s_2])+abs(s[tmp_s_2]-t[tmp_s_2_t-1]), abs(x-s[tmp_s_2])+abs(s[tmp_s_2]-t[tmp_s_2_t]))\n tmp_t_1=bisect.bisect_left(t,x)-1\n tmp_t_2=tmp_t_1+1\n tmp_t_1_s=bisect.bisect_left(s,t[tmp_t_1])\n tmp_t_2_s=bisect.bisect_left(s,t[tmp_t_2])\n ans=min(ans, abs(x-t[tmp_t_1])+abs(t[tmp_t_1]-s[tmp_t_1_s-1]), abs(x-t[tmp_t_1])+abs(t[tmp_t_1]-s[tmp_t_1_s]), abs(x-t[tmp_t_2])+abs(t[tmp_t_2]-s[tmp_t_2_s-1]), abs(x-t[tmp_t_2])+abs(t[tmp_t_2]-s[tmp_t_2_s]))\n print(ans)', 'from bisect import bisect_left\na,b,q=map(int,input().split())\ns=[]\nt=[]\nx=[]\ns.append(-10**12)\nt.append(-10**12)\nfor i in range(a):\n s.append(int(input()))\nfor i in range(b):\n t.append(int(input()))\ns.append(10**12)\nt.append(10**12)\nfor i in range(q):\n x=int(input())\n tmp_s=bisect_left(s,x)-1\n tmp_s_1=s[tmp_s]\n tmp_s_2=s[tmp_s+1]\n tmp_t=bisect_left(t,x)-1\n tmp_t_1=t[tmp_t]\n tmp_t_2=t[tmp_t+1]\n print(min(abs(x-tmp_s_1)+abs(tmp_s_1-tmp_t_1),\n abs(x-tmp_s_1)+abs(tmp_s_1-tmp_t_2),\n abs(x-tmp_s_2)+abs(tmp_s_2-tmp_t_1),\n abs(x-tmp_s_2)+abs(tmp_s_2-tmp_t_2),\n abs(x-tmp_t_1)+abs(tmp_t_1-tmp_s_1),\n abs(x-tmp_t_1)+abs(tmp_t_1-tmp_s_2),\n abs(x-tmp_t_2)+abs(tmp_t_2-tmp_s_1),\n abs(x-tmp_t_2)+abs(tmp_t_2-tmp_s_2)))']
['Runtime Error', 'Accepted']
['s604139134', 's582093881']
[11064.0, 12080.0]
[357.0, 1539.0]
[1083, 761]
p03112
u282228874
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
["from bisect import bisect_left\nimport sys\ninput = sys.stdin.readline\na,b,q = map(int,input().split())\ninf = float('inf')\nS = [-inf]+[int(input()) for i in range(a)]+[inf]\nT = [-inf]+[int(input()) for i in range(b)]+[inf]\n\ndef f(S,T):\n res = 10**30 \n s = bisect_left(S,x)\n res = []\n\n for i in range(2):\n \tfor j in range(2):\n t = bisect_left(T,S[s-i])\n res.append(abs(x-S[s-i])+abs(S[s-i]-T[t-j]))\n\n return min(res)\n\nfor i in range(q):\n x = int(input())\n print(min(f(S,T),f(T,S)))", "import bisect,sys\ninput = sys.stdin.readline\na,b,q = map(int,input().split())\nINF = float('inf')\nS = [-INF]+[int(input()) for i in range(a)]+[INF]\nT = [-INF]+[int(input()) for i in range(b)]+[INF]\n\ndef f(S,T):\n res = INF\n s = bisect.bisect_left(S,x)\n for i in range(2):\n \tfor j in range(2):\n t = bisect.bisect_left(T,S[s-i])\n ans= abs(x-S[s-i])+abs(S[s-i]-T[t-j])\n if ans < res:\n res = ans\n return res\n\nfor i in range(q):\n x = int(input())\n print(min(f(S,T),f(T,S)))\n"]
['Wrong Answer', 'Accepted']
['s478419579', 's732860208']
[14480.0, 13952.0]
[1653.0, 1583.0]
[524, 536]
p03112
u284854859
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['#AVL\n\n##search(0,x):O(logN)\n\ndef search(root,key):\n if avl_key[root] > key:\n if avl_left[root] == None:\n return None\n else:\n return search(avl_left[root],key)\n if avl_key[root] < key:\n if avl_right[root] == None:\n return None\n else:\n return search(avl_right[root],key)\n return root\n\n\n##search_lower(0,x,None):O(logN)\n\ndef search_lower(root,key,lower_key):\n if avl_key[root] > key:\n if avl_left[root] == None:\n return lower_key\n else:\n return search_lower(avl_left[root],key,lower_key)\n if avl_key[root] < key:\n lower_key = avl_key[root]\n if avl_right[root] == None:\n return lower_key\n else:\n return search_lower(avl_right[root],key,lower_key)\n \n # == \n return key\n\n\n\ndef search_higher(root,key,higher_key):\n if avl_key[root] > key:\n higher_key = avl_key[root]\n if avl_left[root] == None:\n return higher_key\n else:\n return search_higher(avl_left[root],key,higher_key)\n if avl_key[root] < key:\n if avl_right[root] == None:\n return higher_key\n else:\n return search_higher(avl_right[root],key,higher_key)\n \n # == \n return key\n\n\n\n\ndef DoubleRightRotation(x):\n tl = avl_left[x]\n avl_left[x] = avl_right[avl_right[tl]]\n avl_right[avl_right[tl]] = x\n tlr = avl_right[tl]\n avl_right[tl] = avl_left[tlr]\n avl_left[tlr] = tl\n if balance[tlr] == -1:\n balance[avl_right[tlr]] = 1\n balance[avl_left[tlr]] = 0\n elif balance[tlr] == 1:\n balance[avl_right[tlr]] = 0\n balance[avl_left[tlr]] = -1\n else:\n balance[avl_right[tlr]] = 0\n balance[avl_left[tlr]] = 0\n balance[tlr] = 0\n return tlr\n\ndef DoubleLeftRotation(x):\n tr = avl_right[x]\n avl_right[x] = avl_left[avl_left[tr]]\n avl_left[avl_left[tr]] = x\n trl = avl_left[tl]\n avl_left[tr] = avl_right[trl]\n avl_right[trl] = tr\n if balance[trl] == 1:\n balance[avl_right[trl]] = 0\n balance[avl_left[trl]] = -1\n elif balance[trl] == -1:\n balance[avl_left[trl]] = 0\n balance[avl_right[trl]] = 1\n else:\n balance[avl_right[trl]] = 0\n balance[avl_left[trl]] = 0\n balance[trl] = 0\n return trl\n\ndef SingleLeftRotation(x):\n tr = avl_right[x]\n balance[tr] = 0\n balance[x] = 0\n avl_right[x] = avl_left[tr]\n avl_left[tr] = x\n return tr\n\ndef SingleRightRotaion(x):\n tl = avl_left[x]\n balance[tl] = 0\n balance[x] = 0\n avl_left[x] = avl_right[tl]\n avl_right[tl] = x\n return tl\n\ndef replace(x,p,v):\n if avl_left[p] == x:\n avl_left[p] = v\n else:\n avl_right[p] = v\n\ndef insertx(root,p,key):\n if avl_key[root] > key:\n if avl_left[root] == None:\n avl_key.append(key)\n avl_left[root] = len(avl_key)-1\n else:\n if not insertx(avl_left[root],root,key):\n return False\n if balance[root] == 1:\n balance[root] = 0\n return False\n elif balance[root] == 0:\n balance[root] = -1\n return True\n else:\n if balance[avl_left[root]] == 1:\n replace(root,p,DoubleRightRotation(root))\n elif balance[avl_left[root]] == -1:\n replace(root,p,SingleRightRotation(root))\n return False\n if avl_key[root] < key:\n if avl_right[root] == None:\n avl_key.append(key)\n avl_right[root] = len(avl_key)-1\n else:\n if not insertx(avl_right[root],root,key):\n return False\n if balance[root] == -1:\n balance[root] = 0\n return False\n elif balance[root] == 0:\n balance[root] = 1\n return True\n else:\n if balance[avl_right[root]] == -1:\n replace(root,p,DoubleLeftRotation(root))\n elif balance[avl_right[root]] == 1:\n replace(root,p,SingleLeftRotation(root))\n return False\n return False\n\n\n##insert(0,x):O(logN)\n\ndef insert(root,key):\n if key < avl_key[root]:\n if avl_left[root] == None:\n avl_key.append(key)\n avl_left[root] = len(avl_key)-1\n else:\n insertx(avl_left[root],root,key)\n elif key > avl_key[root]:\n if avl_right[root] == None:\n avl_key.append(key)\n avl_right[root] = len(avl_key)-1\n else:\n insertx(avl_right[root],root,key)\n else:\n pass\n\n########################################################\n\n\n\n#balance[i]: {"Even":0,"Left":-1,"Right":1}\n\n\na,b,q = map(int,input().split())\ns = [int(input()) for i in range(a)]\nt = [int(input()) for i in range(b)]\nx = [int(input()) for i in range(q)]\n\navl_key = [s[0]]\navl_left = [None]*(a+2)\navl_right = [None]*(a+2)\nbalance = [0]*(a+2)\nfor i in range(1,a):\n insert(0,s[i])\ninsert(0,float("inf"))\ninsert(0,-float("inf"))\n\nfor i in range(q):\n print(search_higher(0,x[i],None))\n print(search_lower(0,x[i],None))\n\navl_key = [t[0]]\navl_left = [None]*(b+2)\navl_right = [None]*(b+2)\nbalance = [0]*(b+2)\nfor i in range(1,b):\n insert(0,t[i])\ninsert(0,float("inf"))\ninsert(0,-float("inf"))\nfor i in range(q):\n print(search_higher(0,x[i],None))\n print(search_lower(0,x[i],None))\n', 'import sys\ninput = sys.stdin.readline\n#AVL\n\n##search(0,x):O(logN)\n\ndef search(root,key):\n if avl[root][0] > key:\n if avl[root][1] == None:\n return None\n else:\n return search(avl[root][1],key)\n if avl[root][0] < key:\n if avl[root][2] == None:\n return None\n else:\n return search(avl[root][2],key)\n return root\n\n\n\ndef end_lower(root):\n if avl[root][1] == None:\n return avl[root][0]\n else:\n return end_lower(avl[root][1])\n\ndef end_higher(root):\n if avl[root][2] == None:\n return avl[root][0]\n else:\n return end_higher(avl[root][2])\n\n\n##search_lower(0,x,None):O(logN)\n\ndef search_lower(root,key,lower_key):\n if avl[root][0] > key:\n if avl[root][1] == None:\n return lower_key\n else:\n return search_lower(avl[root][1],key,lower_key)\n if avl[root][0] < key:\n lower_key = avl[root][0]\n if avl[root][2] == None:\n return lower_key\n else:\n return search_lower(avl[root][2],key,lower_key)\n \n # == \n if avl[root][1] == None:\n return lower_key\n else:\n if lower_key == None:\n return end_higher(avl[root][1])\n else:\n return max(lower_key,end_higher[root][1])\n\n\n\ndef search_higher(root,key,higher_key):\n if avl[root][0] > key:\n higher_key = avl[root][0]\n if avl[root][1] == None:\n return higher_key\n else:\n return search_higher(avl[root][1],key,higher_key)\n if avl[root][0] < key:\n if avl[root][2] == None:\n return higher_key\n else:\n return search_higher(avl[root][2],key,higher_key)\n \n # == \n if avl[root][1] == None:\n return higher_key\n else:\n if higher_key == None:\n return end_lower(avl[root][1])\n else:\n return min(higher_key,end_lower[root][1])\n\n##search_less(0,x,None):O(logN)\n\ndef search_less(root,key,lower_key):\n if avl[root][0] > key:\n if avl[root][1] == None:\n return lower_key\n else:\n return search_less(avl[root][1],key,lower_key)\n if avl[root][0] < key:\n lower_key = avl[root][0]\n if avl[root][2] == None:\n return lower_key\n else:\n return search_less(avl[root][2],key,lower_key)\n \n # == \n return key\n\n##search_more(0,x,None):O(logN)\n\ndef search_more(root,key,higher_key):\n if avl[root][0] > key:\n higher_key = avl[root][0]\n if avl[root][1] == None:\n return higher_key\n else:\n return search_more(avl[root][1],key,higher_key)\n if avl[root][0] < key:\n if avl[root][2] == None:\n return higher_key\n else:\n return search_more(avl[root][2],key,higher_key)\n \n # == \n return key\n\n\n\ndef DoubleRightRotation(x):\n tl = avl[x][1]\n avl[x][1] = avl[avl[tl][2]][2]\n avl[avl[tl][2]][2] = x\n tlr = avl[tl][2]\n avl[tl][2] = avl[tlr][1]\n avl[tlr][1] = tl\n if balance[tlr] == -1:\n balance[avl[tlr][2]] = 1\n balance[avl[tlr][1]] = 0\n elif balance[tlr] == 1:\n balance[avl[tlr][2]] = 0\n balance[avl[tlr][1]] = -1\n else:\n balance[avl[tlr][2]] = 0\n balance[avl[tlr][1]] = 0\n balance[tlr] = 0\n return tlr\n\ndef DoubleLeftRotation(x):\n tr = avl[x][2]\n avl[x][2] = avl[avl[tr][1]][1]\n avl[avl[tr][1]][1] = x\n trl = avl[tl][1]\n avl[tr][1] = avl[trl][2]\n avl[trl][2] = tr\n if balance[trl] == 1:\n balance[avl[trl][2]] = 0\n balance[avl[trl][1]] = -1\n elif balance[trl] == -1:\n balance[avl[trl][1]] = 0\n balance[avl[trl][2]] = 1\n else:\n balance[avl[trl][2]] = 0\n balance[avl[trl][1]] = 0\n balance[trl] = 0\n return trl\n\ndef SingleLeftRotation(x):\n tr = avl[x][2]\n balance[tr] = 0\n balance[x] = 0\n avl[x][2] = avl[tr][1]\n avl[tr][1] = x\n return tr\n\ndef SingleRightRotaion(x):\n tl = avl[x][1]\n balance[tl] = 0\n balance[x] = 0\n avl[x][1] = avl[tl][2]\n avl[tl][2] = x\n return tl\n\ndef replace(x,p,v):\n if avl[p][1] == x:\n avl[p][1] = v\n else:\n avl[p][2] = v\n\ndef insertx(root,p,key):\n if avl[root][0] > key:\n if avl[root][1] == None:\n avl.append([key,None,None])\n avl[root][1] = len(avl)-1\n else:\n if not insertx(avl[root][1],root,key):\n return False\n if balance[root] == 1:\n balance[root] = 0\n return False\n elif balance[root] == 0:\n balance[root] = -1\n return True\n else:\n if balance[avl[root][1]] == 1:\n replace(root,p,DoubleRightRotation(root))\n elif balance[avl[root][1]] == -1:\n replace(root,p,SingleRightRotation(root))\n return False\n if avl[root][0] < key:\n if avl[root][2] == None:\n avl.append([key,None,None])\n avl[root][2] = len(avl)-1\n else:\n if not insertx(avl[root][2],root,key):\n return False\n if balance[root] == -1:\n balance[root] = 0\n return False\n elif balance[root] == 0:\n balance[root] = 1\n return True\n else:\n if balance[avl[root][2]] == -1:\n replace(root,p,DoubleLeftRotation(root))\n elif balance[avl[root][2]] == 1:\n replace(root,p,SingleLeftRotation(root))\n return False\n return False\n\n\n##insert(0,x):O(logN)\n\ndef insert(root,key):\n if key < avl[root][0]:\n if avl[root][1] == None:\n avl.append([key,None,None])\n avl[root][1] = len(avl)-1\n else:\n insertx(avl[root][1],root,key)\n elif key > avl[root][0]:\n if avl[root][2] == None:\n avl.append([key,None,None])\n avl[root][2] = len(avl)-1\n else:\n insertx(avl[root][2],root,key)\n else:\n pass\n\n########################################################\n\nimport sys\ninput = sys.stdin.readline\na,b,q = map(int,input().split())\ns = [int(input()) for i in range(a)]\n#avl[i]:[key,left_index,right_index]\n#balance[i]: {"Even":0,"Left":-1,"Right":1}\n\n#N_MAX = 1000000000\navl = [[s[0],None,None]]\nbalance = [0]*(a)\n\n\n#avl.append(first_avl)\n\nfor i in range(1,a):\n insert(0,s[i])\nprint(1)', '#AVL\n\n##search(0,x):O(logN)\n\ndef search(root,key):\n if avl_key[root] > key:\n if avl_left[root] == None:\n return None\n else:\n return search(avl_left[root],key)\n if avl_key[root] < key:\n if avl_right[root] == None:\n return None\n else:\n return search(avl_right[root],key)\n return root\n\n\n\ndef end_lower(root):\n if avl_left[root] == None:\n return avl_key[root]\n else:\n return end_lower(avl_left[root])\n\ndef end_higher(root):\n if avl_right[root] == None:\n return avl_key[root]\n else:\n return end_higher(avl_right[root])\n\n\n##search_lower(0,x,None):O(logN)\n\ndef search_lower(root,key,lower_key):\n if avl_key[root] > key:\n if avl_left[root] == None:\n return lower_key\n else:\n return search_lower(avl_left[root],key,lower_key)\n if avl_key[root] < key:\n lower_key = avl_key[root]\n if avl_right[root] == None:\n return lower_key\n else:\n return search_lower(avl_right[root],key,lower_key)\n \n # == \n if avl_left[root] == None:\n return lower_key\n else:\n if lower_key == None:\n return end_higher(avl_left[root])\n else:\n return max(lower_key,end_higher(avl_left[root]))\n\n\n\ndef search_higher(root,key,higher_key):\n if avl_key[root] > key:\n higher_key = avl_key[root]\n if avl_left[root] == None:\n return higher_key\n else:\n return search_higher(avl_left[root],key,higher_key)\n if avl_key[root] < key:\n if avl_right[root] == None:\n return higher_key\n else:\n return search_higher(avl_right[root],key,higher_key)\n \n # == \n if avl_right[root] == None:\n return higher_key\n else:\n if higher_key == None:\n return end_lower(avl_right[root])\n else:\n return min(higher_key,end_lower(avl_right[root]))\n\n\n\n\ndef DoubleRightRotation(x):\n tl = avl_left[x]\n avl_left[x] = avl_right[avl_right[tl]]\n avl_right[avl_right[tl]] = x\n tlr = avl_right[tl]\n avl_right[tl] = avl_left[tlr]\n avl_left[tlr] = tl\n if balance[tlr] == -1:\n balance[avl_right[tlr]] = 1\n balance[avl_left[tlr]] = 0\n elif balance[tlr] == 1:\n balance[avl_right[tlr]] = 0\n balance[avl_left[tlr]] = -1\n else:\n balance[avl_right[tlr]] = 0\n balance[avl_left[tlr]] = 0\n balance[tlr] = 0\n return tlr\n\ndef DoubleLeftRotation(x):\n tr = avl_right[x]\n avl_right[x] = avl_left[avl_left[tr]]\n avl_left[avl_left[tr]] = x\n trl = avl_left[tl]\n avl_left[tr] = avl_right[trl]\n avl_right[trl] = tr\n if balance[trl] == 1:\n balance[avl_right[trl]] = 0\n balance[avl_left[trl]] = -1\n elif balance[trl] == -1:\n balance[avl_left[trl]] = 0\n balance[avl_right[trl]] = 1\n else:\n balance[avl_right[trl]] = 0\n balance[avl_left[trl]] = 0\n balance[trl] = 0\n return trl\n\ndef SingleLeftRotation(x):\n tr = avl_right[x]\n balance[tr] = 0\n balance[x] = 0\n avl_right[x] = avl_left[tr]\n avl_left[tr] = x\n return tr\n\ndef SingleRightRotaion(x):\n tl = avl_left[x]\n balance[tl] = 0\n balance[x] = 0\n avl_left[x] = avl_right[tl]\n avl_right[tl] = x\n return tl\n\ndef replace(x,p,v):\n if avl_left[p] == x:\n avl_left[p] = v\n else:\n avl_right[p] = v\n\ndef insertx(root,p,key):\n if avl_key[root] > key:\n if avl_left[root] == None:\n avl_key.append(key)\n avl_left[root] = len(avl_key)-1\n else:\n if not insertx(avl_left[root],root,key):\n return False\n if balance[root] == 1:\n balance[root] = 0\n return False\n elif balance[root] == 0:\n balance[root] = -1\n return True\n else:\n if balance[avl_left[root]] == 1:\n replace(root,p,DoubleRightRotation(root))\n elif balance[avl_left[root]] == -1:\n replace(root,p,SingleRightRotation(root))\n return False\n if avl_key[root] < key:\n if avl_right[root] == None:\n avl_key.append(key)\n avl_right[root] = len(avl_key)-1\n else:\n if not insertx(avl_right[root],root,key):\n return False\n if balance[root] == -1:\n balance[root] = 0\n return False\n elif balance[root] == 0:\n balance[root] = 1\n return True\n else:\n if balance[avl_right[root]] == -1:\n replace(root,p,DoubleLeftRotation(root))\n elif balance[avl_right[root]] == 1:\n replace(root,p,SingleLeftRotation(root))\n return False\n return False\n\n\n##insert(0,x):O(logN)\n\ndef insert(root,key):\n if key < avl_key[root]:\n if avl_left[root] == None:\n avl_key.append(key)\n avl_left[root] = len(avl_key)-1\n else:\n insertx(avl_left[root],root,key)\n elif key > avl_key[root]:\n if avl_right[root] == None:\n avl_key.append(key)\n avl_right[root] = len(avl_key)-1\n else:\n insertx(avl_right[root],root,key)\n else:\n pass\n\n########################################################\n\n\n\n#balance[i]: {"Even":0,"Left":-1,"Right":1}\n\n\na,b,q = map(int,input().split())\ns = [int(input()) for i in range(a)]\navl_key = [s]\navl_left = [None]*a\navl_right = [None]*a\nbalance = [0]*a\n\nfor i in range(1,a):\n insert(0,s[i])\nt = [int(input()) for i in range(b)]\navl_key = [t[0]]\navl_left = [None]*b\navl_right = [None]*b\nbalance = [0]*b\nfor i in range(1,b):\n insert(0,t[i])\n\nprint(1)', 'import sys\n# coding: utf-8\n#\n\n#\n# Copyright (C) 2007 Makoto Hiroi\n#\n\n\nclass Node:\n def __init__(self, x):\n self.data = x\n self.left = None\n self.right = None\n\n\ndef rotate_right(node):\n lnode = node.left\n node.left = lnode.right\n lnode.right = node\n return lnode\n\n\ndef rotate_left(node):\n rnode = node.right\n node.right = rnode.left\n rnode.left = node\n return rnode\n\n\ndef search(node, x):\n while node is not None:\n if node.data == x: return True\n if x < node.data:\n node = node.left\n else:\n node = node.right\n return False\n\n\ndef insert(node, x):\n if node is None: return Node(x)\n p = node\n while True:\n if p.data == x: return node\n elif x < p.data:\n if p.left is None:\n p.left = Node(x)\n break\n p = p.left\n else:\n if p.right is None:\n p.right = Node(x)\n break\n p = p.right\n return node\n\n#\n\n#\n\n\ndef _search(node, x):\n pnode = None\n while node is not None:\n if node.data == x: return node, pnode\n pnode = node\n if x < node.data:\n node = node.left\n else:\n node = node.right\n return None, None\n\n\ndef _search_min(node):\n pnode = None\n while node.left is not None:\n pnode = node\n node = node.left\n return node, pnode\n\n\ndef delete(root, x):\n if root is None: return None \n node, pnode = _search(root, x) \n if node is None: return root データなし\n if node.left is not None and node.right is not None:\n \n \n min_node, min_pnode = _search_min(node.right)\n node.data = min_node.data\n if min_pnode is not None:\n pnode = min_pnode\n node = min_node\n else:\n pnode = node\n node = min_node\n \n if node.left is None:\n cnode = node.right\n else:\n cnode = node.left\n if pnode is None:\n return cnode \n elif pnode.left == node:\n pnode.left = cnode\n else:\n pnode.right = cnode\n return root\n\n\ndef traverse(node):\n if node is not None:\n for x in traverse(node.left):\n yield x\n yield node.data\n for x in traverse(node.right):\n yield x\n \ninput = sys.stdin.readline\na, b, q = map(int,input().split())\ns = [int(input()) for i in range(a)]\nt = [int(input()) for i in range(b)]\nx = [int(input()) for i in range(q)]\nlens, lent = len(s), len(t)\ntreeA= Node(s[0])\nfor i in range(1,lens): \n insert(treeA,s[i]) \ntreeB= Node(t[0])\nfor i in range(lent):\n insert(treeB,t[i])\nprint(1)\n', 'import bisect\nimport sys\n \nclass Avltree:\n def __init__(self,key=None):\n self.key = key\n self.left = None\n self.right = None \n self.balance = "Even"\n def search(self,key):\n if self.key == None:\n return None\n if self.key > key:\n if self.left == None:\n return None\n else:\n return self.left.search(key)\n if self.key < key:\n if self.right == None:\n return None\n else:\n return self.right.search(key)\n return self \n \n def search_lower(self,key,key_lower):\n if self.key == None:\n return key_lower\n if self.key > key:\n if self.left == None:\n return key_lower\n else:\n return self.left.search_lower(key,key_lower)\n if self.key < key:\n key_lower = self.key\n if self.right == None:\n return key_lower\n else:\n return self.right.search_lower(key,key_lower)\n \n if self.left == None:\n return key_lower\n else:\n if key_lower == None:\n return self.left.end_higher(self.left.key)\n else:\n return max(key_lower,self.left.end_higher(self.left.key))\n \n def search_higher(self,key,key_higher):\n if self.key == None:\n return key_higher\n if self.key > key:\n key_higher = self.key\n if self.left == None:\n return key_higher\n else:\n return self.left.search_higher(key,key_higher)\n if self.key < key:\n if self.right == None:\n return key_higher\n else:\n return self.right.search_higher(key,key_higher)\n \n if self.right == None:\n return key_higher\n else:\n if key_higher == None:\n return self.right.end_lower(self.right.key)\n else:\n return min(key_higher,self.right.end_lower(self.right.key))\n \n \n def end_lower(self,end_lower_key):\n if self.left == None:\n return end_lower_key\n else:\n end_lower_key = self.left.key\n return self.left.end_lower(end_lower_key)\n def end_higher(self,end_higher_key):\n if self.right == None:\n return end_higher_key\n else:\n end_higher_key = self.right.key\n return self.right.end_higher(end_higher_key)\n \n \n def DoubleRightRotation(self):\n tl = self.left\n self.left = tl.right.right\n tl.right.right = self \n tlr = tl.right\n tl.right = tlr.left\n tlr.left = tl\n if tlr.balance == "Left":\n tlr.right.balance = "Right"\n tlr.left.balance = "Even"\n elif tlr.balance == "Right":\n tlr.right.balance = "Even"\n tlr.left.balance = "Left"\n elif tlr.balance == "Even":\n tlr.right.balance = "Even"\n tlr.left.balance = "Even"\n tlr.balance = "Even"\n return tlr\n def DoubleLeftRotation(self):\n tr = self.right\n self.right = tr.left.left\n tr.left.left = self\n trl = tr.left\n tr.left = trl.right\n trl.right = tr\n if trl.balance == "Right":\n trl.left.balance = "Left"\n trl.right.balance = "Even"\n elif trl.balance == "Left":\n trl.left.balance = "Even"\n trl.right.balance = "Right"\n elif trl.balance == "Even":\n trl.left.balance = "Even"\n trl.right.balance = "Even"\n trl.balance = "Even"\n return trl\n def SingleLeftRotation(self):\n tr = self.right\n tr.balance = "Even"\n self.balance = "Even"\n self.right = tr.left\n tr.left = self\n return tr\n def SingleRightRotation(self):\n tl = self.left\n tl.balance = "Even"\n self.balance = "Even"\n self.left = tl.right\n tl.right = self\n return tl\n def replace(self,p,v): \n if p.left == self:\n p.left = v\n else :\n p.right = v \n def insert(self,key): \n if self.key == None: \n self.key = key\n return self\n if key < self.key:\n if self.left == None:\n self.left = Avltree(key)\n else:\n self.left.insertx(self,key)\n elif key > self.key:\n if self.right == None:\n self.right = Avltree(key)\n else:\n self.right.insertx(self,key)\n else: # key == self.key:\n pass # do not overwrite\n def insertx(self,p,key): \n if self.key > key:\n if self.left == None:\n self.left = Avltree(key)\n else:\n if not self.left.insertx(self, key): \n return False \n if self.balance == "Right":\n self.balance = "Even"\n return False\n elif self.balance == "Even":\n self.balance = "Left"\n return True \n elif self.balance == "Left":\n if self.left.balance == "Right":\n self.replace(p,self.DoubleRightRotation())\n elif self.left.balance == "Left":\n self.replace(p,self.SingleRightRotation())\n return False \n if self.key < key:\n if self.right == None:\n self.right = Avltree(key)\n else:\n if not self.right.insertx(self, key):\n return False \n if self.balance == "Left":\n self.balance = "Even"\n return False\n elif self.balance == "Even":\n self.balance = "Right"\n return True\n elif self.balance == "Right":\n if self.right.balance == "Left": \n self.replace(p,self.DoubleLeftRotation())\n elif self.right.balance == "Right":\n self.replace(p,self.SingleLeftRotation())\n return False\n return False \n \n def to_s(self):\n return self.key\n def left_s(self):\n if self.left == None:\n return None\n return (self.left).key\n def right_s(self):\n if self.right == None:\n return None\n return (self.right).key\n \ninput = sys.stdin.readline\na, b, q = map(int,input().split())\ns = [int(input()) for i in range(a)]\nt = [int(input()) for i in range(b)]\nx = [int(input()) for i in range(q)]\nlens, lent = len(s), len(t)\ntreeA, treeB = Avltree(), Avltree()\nfor i in s: treeA.insert(i) \nfor i in t: treeB.insert(i)\n \nprint(1)', 'import sys\n \nclass Avltree:\n def __init__(self,key=None):\n self.key = key\n self.left = None\n self.right = None \n self.balance = "Even"\n def search(self,key):\n if self.key == None:\n return None\n if self.key > key:\n if self.left == None:\n return None\n else:\n return self.left.search(key)\n if self.key < key:\n if self.right == None:\n return None\n else:\n return self.right.search(key)\n return self \n \n def search_lower(self,key,key_lower):\n if self.key == None:\n return key_lower\n if self.key > key:\n if self.left == None:\n return key_lower\n else:\n return self.left.search_lower(key,key_lower)\n if self.key < key:\n key_lower = self.key\n if self.right == None:\n return key_lower\n else:\n return self.right.search_lower(key,key_lower)\n \n if self.left == None:\n return key_lower\n else:\n if key_lower == None:\n return self.left.end_higher(self.left.key)\n else:\n return max(key_lower,self.left.end_higher(self.left.key))\n \n def search_higher(self,key,key_higher):\n if self.key == None:\n return key_higher\n if self.key > key:\n key_higher = self.key\n if self.left == None:\n return key_higher\n else:\n return self.left.search_higher(key,key_higher)\n if self.key < key:\n if self.right == None:\n return key_higher\n else:\n return self.right.search_higher(key,key_higher)\n \n if self.right == None:\n return key_higher\n else:\n if key_higher == None:\n return self.right.end_lower(self.right.key)\n else:\n return min(key_higher,self.right.end_lower(self.right.key))\n \n \n def end_lower(self,end_lower_key):\n if self.left == None:\n return end_lower_key\n else:\n end_lower_key = self.left.key\n return self.left.end_lower(end_lower_key)\n def end_higher(self,end_higher_key):\n if self.right == None:\n return end_higher_key\n else:\n end_higher_key = self.right.key\n return self.right.end_higher(end_higher_key)\n \n \n def DoubleRightRotation(self):\n tl = self.left\n self.left = tl.right.right\n tl.right.right = self \n tlr = tl.right\n tl.right = tlr.left\n tlr.left = tl\n if tlr.balance == "Left":\n tlr.right.balance = "Right"\n tlr.left.balance = "Even"\n elif tlr.balance == "Right":\n tlr.right.balance = "Even"\n tlr.left.balance = "Left"\n elif tlr.balance == "Even":\n tlr.right.balance = "Even"\n tlr.left.balance = "Even"\n tlr.balance = "Even"\n return tlr\n def DoubleLeftRotation(self):\n tr = self.right\n self.right = tr.left.left\n tr.left.left = self\n trl = tr.left\n tr.left = trl.right\n trl.right = tr\n if trl.balance == "Right":\n trl.left.balance = "Left"\n trl.right.balance = "Even"\n elif trl.balance == "Left":\n trl.left.balance = "Even"\n trl.right.balance = "Right"\n elif trl.balance == "Even":\n trl.left.balance = "Even"\n trl.right.balance = "Even"\n trl.balance = "Even"\n return trl\n def SingleLeftRotation(self):\n tr = self.right\n tr.balance = "Even"\n self.balance = "Even"\n self.right = tr.left\n tr.left = self\n return tr\n def SingleRightRotation(self):\n tl = self.left\n tl.balance = "Even"\n self.balance = "Even"\n self.left = tl.right\n tl.right = self\n return tl\n def replace(self,p,v): \n if p.left == self:\n p.left = v\n else :\n p.right = v \n def insert(self,key): \n if self.key == None: \n self.key = key\n return self\n if key < self.key:\n if self.left == None:\n self.left = Avltree(key)\n else:\n self.left.insertx(self,key)\n elif key > self.key:\n if self.right == None:\n self.right = Avltree(key)\n else:\n self.right.insertx(self,key)\n else: # key == self.key:\n pass # do not overwrite\n def insertx(self,p,key): \n if self.key > key:\n if self.left == None:\n self.left = Avltree(key)\n else:\n if not self.left.insertx(self, key): \n return False \n if self.balance == "Right":\n self.balance = "Even"\n return False\n elif self.balance == "Even":\n self.balance = "Left"\n return True \n elif self.balance == "Left":\n if self.left.balance == "Right":\n self.replace(p,self.DoubleRightRotation())\n elif self.left.balance == "Left":\n self.replace(p,self.SingleRightRotation())\n return False \n if self.key < key:\n if self.right == None:\n self.right = Avltree(key)\n else:\n if not self.right.insertx(self, key):\n return False \n if self.balance == "Left":\n self.balance = "Even"\n return False\n elif self.balance == "Even":\n self.balance = "Right"\n return True\n elif self.balance == "Right":\n if self.right.balance == "Left": \n self.replace(p,self.DoubleLeftRotation())\n elif self.right.balance == "Right":\n self.replace(p,self.SingleLeftRotation())\n return False\n return False \n \n def to_s(self):\n return self.key\n def left_s(self):\n if self.left == None:\n return None\n return (self.left).key\n def right_s(self):\n if self.right == None:\n return None\n return (self.right).key\n \ninput = sys.stdin.readline\na, b, q = map(int,input().split())\ns = [int(input()) for i in range(a)]\nt = [int(input()) for i in range(a)]\ntreeA,treeB = Avltree(),Avltree()\nfor i in s: treeA.insert(i)\nfor i in t: treeB.insert(i)\nprint(1)', 'import sys\ninput = sys.stdin.readline\n#AVL\n\n##search(0,x):O(logN)\n\ndef search(root,key):\n if avl[root][0] > key:\n if avl[root][1] == None:\n return None\n else:\n return search(avl[root][1],key)\n if avl[root][0] < key:\n if avl[root][2] == None:\n return None\n else:\n return search(avl[root][2],key)\n return root\n\n\n\ndef end_lower(root):\n if avl[root][1] == None:\n return avl[root][0]\n else:\n return end_lower(avl[root][1])\n\ndef end_higher(root):\n if avl[root][2] == None:\n return avl[root][0]\n else:\n return end_higher(avl[root][2])\n\n\n##search_lower(0,x,None):O(logN)\n\ndef search_lower(root,key,lower_key):\n if avl[root][0] > key:\n if avl[root][1] == None:\n return lower_key\n else:\n return search_lower(avl[root][1],key,lower_key)\n if avl[root][0] < key:\n lower_key = avl[root][0]\n if avl[root][2] == None:\n return lower_key\n else:\n return search_lower(avl[root][2],key,lower_key)\n \n # == \n if avl[root][1] == None:\n return lower_key\n else:\n if lower_key == None:\n return end_higher(avl[root][1])\n else:\n return max(lower_key,end_higher[root][1])\n\n\n\ndef search_higher(root,key,higher_key):\n if avl[root][0] > key:\n higher_key = avl[root][0]\n if avl[root][1] == None:\n return higher_key\n else:\n return search_higher(avl[root][1],key,higher_key)\n if avl[root][0] < key:\n if avl[root][2] == None:\n return higher_key\n else:\n return search_higher(avl[root][2],key,higher_key)\n \n # == \n if avl[root][1] == None:\n return higher_key\n else:\n if higher_key == None:\n return end_lower(avl[root][1])\n else:\n return min(higher_key,end_lower[root][1])\n\n##search_less(0,x,None):O(logN)\n\ndef search_less(root,key,lower_key):\n if avl[root][0] > key:\n if avl[root][1] == None:\n return lower_key\n else:\n return search_less(avl[root][1],key,lower_key)\n if avl[root][0] < key:\n lower_key = avl[root][0]\n if avl[root][2] == None:\n return lower_key\n else:\n return search_less(avl[root][2],key,lower_key)\n \n # == \n return key\n\n##search_more(0,x,None):O(logN)\n\ndef search_more(root,key,higher_key):\n if avl[root][0] > key:\n higher_key = avl[root][0]\n if avl[root][1] == None:\n return higher_key\n else:\n return search_more(avl[root][1],key,higher_key)\n if avl[root][0] < key:\n if avl[root][2] == None:\n return higher_key\n else:\n return search_more(avl[root][2],key,higher_key)\n \n # == \n return key\n\n\n\ndef DoubleRightRotation(x):\n tl = avl[x][1]\n avl[x][1] = avl[avl[tl][2]][2]\n avl[avl[tl][2]][2] = x\n tlr = avl[tl][2]\n avl[tl][2] = avl[tlr][1]\n avl[tlr][1] = tl\n if balance[tlr] == -1:\n balance[avl[tlr][2]] = 1\n balance[avl[tlr][1]] = 0\n elif balance[tlr] == 1:\n balance[avl[tlr][2]] = 0\n balance[avl[tlr][1]] = -1\n else:\n balance[avl[tlr][2]] = 0\n balance[avl[tlr][1]] = 0\n balance[tlr] = 0\n return tlr\n\ndef DoubleLeftRotation(x):\n tr = avl[x][2]\n avl[x][2] = avl[avl[tr][1]][1]\n avl[avl[tr][1]][1] = x\n trl = avl[tl][1]\n avl[tr][1] = avl[trl][2]\n avl[trl][2] = tr\n if balance[trl] == 1:\n balance[avl[trl][2]] = 0\n balance[avl[trl][1]] = -1\n elif balance[trl] == -1:\n balance[avl[trl][1]] = 0\n balance[avl[trl][2]] = 1\n else:\n balance[avl[trl][2]] = 0\n balance[avl[trl][1]] = 0\n balance[trl] = 0\n return trl\n\ndef SingleLeftRotation(x):\n tr = avl[x][2]\n balance[tr] = 0\n balance[x] = 0\n avl[x][2] = avl[tr][1]\n avl[tr][1] = x\n return tr\n\ndef SingleRightRotaion(x):\n tl = avl[x][1]\n balance[tl] = 0\n balance[x] = 0\n avl[x][1] = avl[tl][2]\n avl[tl][2] = x\n return tl\n\ndef replace(x,p,v):\n if avl[p][1] == x:\n avl[p][1] = v\n else:\n avl[p][2] = v\n\ndef insertx(root,p,key):\n if avl[root][0] > key:\n if avl[root][1] == None:\n avl.append([key,None,None])\n avl[root][1] = len(avl)-1\n else:\n if not insertx(avl[root][1],root,key):\n return False\n if balance[root] == 1:\n balance[root] = 0\n return False\n elif balance[root] == 0:\n balance[root] = -1\n return True\n else:\n if balance[avl[root][1]] == 1:\n replace(root,p,DoubleRightRotation(root))\n elif balance[avl[root][1]] == -1:\n replace(root,p,SingleRightRotation(root))\n return False\n if avl[root][0] < key:\n if avl[root][2] == None:\n avl.append([key,None,None])\n avl[root][2] = len(avl)-1\n else:\n if not insertx(avl[root][2],root,key):\n return False\n if balance[root] == -1:\n balance[root] = 0\n return False\n elif balance[root] == 0:\n balance[root] = 1\n return True\n else:\n if balance[avl[root][2]] == -1:\n replace(root,p,DoubleLeftRotation(root))\n elif balance[avl[root][2]] == 1:\n replace(root,p,SingleLeftRotation(root))\n return False\n return False\n\n\n##insert(0,x):O(logN)\n\ndef insert(key):\n if key < avl[0][0]:\n if avl[0][1] == None:\n avl.append([key,None,None])\n avl[0][1] = len(avl)-1\n else:\n insertx(avl[0][1],0,key)\n elif key > avl[0][0]:\n if avl[0][2] == None:\n avl.append([key,None,None])\n avl[0][2] = len(avl)-1\n else:\n insertx(avl[0][2],0,key)\n else:\n pass\n\n########################################################\n\nimport sys\ninput = sys.stdin.readline\na,b,q = map(int,input().split())\ns = [int(input()) for i in range(a)]\n#avl[i]:[key,left_index,right_index]\n#balance[i]: {"Even":0,"Left":-1,"Right":1}\n\n#N_MAX = 1000000000\navl = [[s[0],None,None]]\nbalance = [0]*(a)\n\n\n#avl.append(first_avl)\n\nfor i in range(1,a):\n insert(s[i])\n\n\nt = [int(input()) for i in range(b)]\navl = [[t[0],None,None]]\nbalance = [0]*(b)\nfor i in range(1,b):\n insert(t[i])\nprint(1)', '#AVL\n\n##search(0,x):O(logN)\n\ndef search(root,key):\n if avl_key[root] > key:\n if avl_left[root] == None:\n return None\n else:\n return search(avl_left[root],key)\n if avl_key[root] < key:\n if avl_right[root] == None:\n return None\n else:\n return search(avl_right[root],key)\n return root\n\n\n\ndef end_lower(root):\n if avl_left[root] == None:\n return avl_key[root]\n else:\n return end_lower(avl_left[root])\n\ndef end_higher(root):\n if avl_right[root] == None:\n return avl_key[root]\n else:\n return end_higher(avl_right[root])\n\n\n##search_lower(0,x,None):O(logN)\n\ndef search_lower(root,key,lower_key):\n if avl_key[root] > key:\n if avl_left[root] == None:\n return lower_key\n else:\n return search_lower(avl_left[root],key,lower_key)\n if avl_key[root] < key:\n lower_key = avl_key[root]\n if avl_right[root] == None:\n return lower_key\n else:\n return search_lower(avl_right[root],key,lower_key)\n \n # == \n if avl_left[root] == None:\n return lower_key\n else:\n if lower_key == None:\n return end_higher(avl_left[root])\n else:\n return max(lower_key,end_higher(avl_left[root]))\n\n\n\ndef search_higher(root,key,higher_key):\n if avl_key[root] > key:\n higher_key = avl_key[root]\n if avl_left[root] == None:\n return higher_key\n else:\n return search_higher(avl_left[root],key,higher_key)\n if avl_key[root] < key:\n if avl_right[root] == None:\n return higher_key\n else:\n return search_higher(avl_right[root],key,higher_key)\n \n # == \n if avl_right[root] == None:\n return higher_key\n else:\n if higher_key == None:\n return end_lower(avl_right[root])\n else:\n return min(higher_key,end_lower(avl_right[root]))\n\n\n\n\ndef DoubleRightRotation(x):\n tl = avl_left[x]\n avl_left[x] = avl_right[avl_right[tl]]\n avl_right[avl_right[tl]] = x\n tlr = avl_right[tl]\n avl_right[tl] = avl_left[tlr]\n avl_left[tlr] = tl\n if balance[tlr] == -1:\n balance[avl_right[tlr]] = 1\n balance[avl_left[tlr]] = 0\n elif balance[tlr] == 1:\n balance[avl_right[tlr]] = 0\n balance[avl_left[tlr]] = -1\n else:\n balance[avl_right[tlr]] = 0\n balance[avl_left[tlr]] = 0\n balance[tlr] = 0\n return tlr\n\ndef DoubleLeftRotation(x):\n tr = avl_right[x]\n avl_right[x] = avl_left[avl_left[tr]]\n avl_left[avl_left[tr]] = x\n trl = avl_left[tl]\n avl_left[tr] = avl_right[trl]\n avl_right[trl] = tr\n if balance[trl] == 1:\n balance[avl_right[trl]] = 0\n balance[avl_left[trl]] = -1\n elif balance[trl] == -1:\n balance[avl_left[trl]] = 0\n balance[avl_right[trl]] = 1\n else:\n balance[avl_right[trl]] = 0\n balance[avl_left[trl]] = 0\n balance[trl] = 0\n return trl\n\ndef SingleLeftRotation(x):\n tr = avl_right[x]\n balance[tr] = 0\n balance[x] = 0\n avl_right[x] = avl_left[tr]\n avl_left[tr] = x\n return tr\n\ndef SingleRightRotaion(x):\n tl = avl_left[x]\n balance[tl] = 0\n balance[x] = 0\n avl_left[x] = avl_right[tl]\n avl_right[tl] = x\n return tl\n\ndef replace(x,p,v):\n if avl_left[p] == x:\n avl_left[p] = v\n else:\n avl_right[p] = v\n\ndef insertx(root,p,key):\n if avl_key[root] > key:\n if avl_left[root] == None:\n avl_key.append(key)\n avl_left[root] = len(avl_key)-1\n else:\n if not insertx(avl_left[root],root,key):\n return False\n if balance[root] == 1:\n balance[root] = 0\n return False\n elif balance[root] == 0:\n balance[root] = -1\n return True\n else:\n if balance[avl_left[root]] == 1:\n replace(root,p,DoubleRightRotation(root))\n elif balance[avl_left[root]] == -1:\n replace(root,p,SingleRightRotation(root))\n return False\n if avl_key[root] < key:\n if avl_right[root] == None:\n avl_key.append(key)\n avl_right[root] = len(avl_key)-1\n else:\n if not insertx(avl_right[root],root,key):\n return False\n if balance[root] == -1:\n balance[root] = 0\n return False\n elif balance[root] == 0:\n balance[root] = 1\n return True\n else:\n if balance[avl_right[root]] == -1:\n replace(root,p,DoubleLeftRotation(root))\n elif balance[avl_right[root]] == 1:\n replace(root,p,SingleLeftRotation(root))\n return False\n return False\n\n\n##insert(0,x):O(logN)\n\ndef insert(root,key):\n if key < avl_key[root]:\n if avl_left[root] == None:\n avl_key.append(key)\n avl_left[root] = len(avl_key)-1\n else:\n insertx(avl_left[root],root,key)\n elif key > avl_key[root]:\n if avl_right[root] == None:\n avl_key.append(key)\n avl_right[root] = len(avl_key)-1\n else:\n insertx(avl_right[root],root,key)\n else:\n pass\n\n########################################################\n\n\n\n#balance[i]: {"Even":0,"Left":-1,"Right":1}\n\n\na,b,q = map(int,input().split())\ns = [int(input()) for i in range(a)]\navl_key = [s[0]]\navl_left = [None]*a\navl_right = [None]*a\nbalance = [0]*a\n\nfor i in range(1,a):\n insert(0,s[i])\nt = [int(input()) for i in range(b)]\navl_key = [t[0]]\navl_left = [None]*b\navl_right = [None]*b\nbalance = [0]*b\nfor i in range(1,b):\n insert(0,t[i])\n\nprint(1)', 'import sys\n \nclass Avltree:\n def __init__(self,key=None):\n self.key = key\n self.left = None\n self.right = None \n self.balance = "Even"\n def search(self,key):\n if self.key == None:\n return None\n if self.key > key:\n if self.left == None:\n return None\n else:\n return self.left.search(key)\n if self.key < key:\n if self.right == None:\n return None\n else:\n return self.right.search(key)\n return self \n \n def search_lower(self,key,key_lower):\n if self.key == None:\n return key_lower\n if self.key > key:\n if self.left == None:\n return key_lower\n else:\n return self.left.search_lower(key,key_lower)\n if self.key < key:\n key_lower = self.key\n if self.right == None:\n return key_lower\n else:\n return self.right.search_lower(key,key_lower)\n \n if self.left == None:\n return key_lower\n else:\n if key_lower == None:\n return self.left.end_higher(self.left.key)\n else:\n return max(key_lower,self.left.end_higher(self.left.key))\n \n def search_higher(self,key,key_higher):\n if self.key == None:\n return key_higher\n if self.key > key:\n key_higher = self.key\n if self.left == None:\n return key_higher\n else:\n return self.left.search_higher(key,key_higher)\n if self.key < key:\n if self.right == None:\n return key_higher\n else:\n return self.right.search_higher(key,key_higher)\n \n if self.right == None:\n return key_higher\n else:\n if key_higher == None:\n return self.right.end_lower(self.right.key)\n else:\n return min(key_higher,self.right.end_lower(self.right.key))\n \n \n def end_lower(self,end_lower_key):\n if self.left == None:\n return end_lower_key\n else:\n end_lower_key = self.left.key\n return self.left.end_lower(end_lower_key)\n def end_higher(self,end_higher_key):\n if self.right == None:\n return end_higher_key\n else:\n end_higher_key = self.right.key\n return self.right.end_higher(end_higher_key)\n \n \n def DoubleRightRotation(self):\n tl = self.left\n self.left = tl.right.right\n tl.right.right = self \n tlr = tl.right\n tl.right = tlr.left\n tlr.left = tl\n if tlr.balance == "Left":\n tlr.right.balance = "Right"\n tlr.left.balance = "Even"\n elif tlr.balance == "Right":\n tlr.right.balance = "Even"\n tlr.left.balance = "Left"\n elif tlr.balance == "Even":\n tlr.right.balance = "Even"\n tlr.left.balance = "Even"\n tlr.balance = "Even"\n return tlr\n def DoubleLeftRotation(self):\n tr = self.right\n self.right = tr.left.left\n tr.left.left = self\n trl = tr.left\n tr.left = trl.right\n trl.right = tr\n if trl.balance == "Right":\n trl.left.balance = "Left"\n trl.right.balance = "Even"\n elif trl.balance == "Left":\n trl.left.balance = "Even"\n trl.right.balance = "Right"\n elif trl.balance == "Even":\n trl.left.balance = "Even"\n trl.right.balance = "Even"\n trl.balance = "Even"\n return trl\n def SingleLeftRotation(self):\n tr = self.right\n tr.balance = "Even"\n self.balance = "Even"\n self.right = tr.left\n tr.left = self\n return tr\n def SingleRightRotation(self):\n tl = self.left\n tl.balance = "Even"\n self.balance = "Even"\n self.left = tl.right\n tl.right = self\n return tl\n def replace(self,p,v): \n if p.left == self:\n p.left = v\n else :\n p.right = v \n def insert(self,key): \n if self.key == None: \n self.key = key\n return self\n if key < self.key:\n if self.left == None:\n self.left = Avltree(key)\n else:\n self.left.insertx(self,key)\n elif key > self.key:\n if self.right == None:\n self.right = Avltree(key)\n else:\n self.right.insertx(self,key)\n else: # key == self.key:\n pass # do not overwrite\n def insertx(self,p,key): \n if self.key > key:\n if self.left == None:\n self.left = Avltree(key)\n else:\n if not self.left.insertx(self, key): \n return False \n if self.balance == "Right":\n self.balance = "Even"\n return False\n elif self.balance == "Even":\n self.balance = "Left"\n return True \n elif self.balance == "Left":\n if self.left.balance == "Right":\n self.replace(p,self.DoubleRightRotation())\n elif self.left.balance == "Left":\n self.replace(p,self.SingleRightRotation())\n return False \n if self.key < key:\n if self.right == None:\n self.right = Avltree(key)\n else:\n if not self.right.insertx(self, key):\n return False \n if self.balance == "Left":\n self.balance = "Even"\n return False\n elif self.balance == "Even":\n self.balance = "Right"\n return True\n elif self.balance == "Right":\n if self.right.balance == "Left": \n self.replace(p,self.DoubleLeftRotation())\n elif self.right.balance == "Right":\n self.replace(p,self.SingleLeftRotation())\n return False\n return False \n \n def to_s(self):\n return self.key\n def left_s(self):\n if self.left == None:\n return None\n return (self.left).key\n def right_s(self):\n if self.right == None:\n return None\n return (self.right).key\n \ninput = sys.stdin.readline\na, b, q = map(int,input().split())\ns = [int(input()) for i in range(a)]\nt = [int(input()) for i in range(b)]\ntreeA,treeB = Avltree(),Avltree()\nfor i in s: treeA.insert(i)\nfor i in t: treeB.insert(i)\nprint(1)', 'import sys\ninput = sys.stdin.readline\n#AVL\n\n##search(0,x):O(logN)\n\ndef search(root,key):\n if avl[root][0] > key:\n if avl[root][1] == None:\n return None\n else:\n return search(avl[root][1],key)\n if avl[root][0] < key:\n if avl[root][2] == None:\n return None\n else:\n return search(avl[root][2],key)\n return root\n\n\n\ndef end_lower(root):\n if avl[root][1] == None:\n return avl[root][0]\n else:\n return end_lower(avl[root][1])\n\ndef end_higher(root):\n if avl[root][2] == None:\n return avl[root][0]\n else:\n return end_higher(avl[root][2])\n\n\n##search_lower(0,x,None):O(logN)\n\ndef search_lower(root,key,lower_key):\n if avl[root][0] > key:\n if avl[root][1] == None:\n return lower_key\n else:\n return search_lower(avl[root][1],key,lower_key)\n if avl[root][0] < key:\n lower_key = avl[root][0]\n if avl[root][2] == None:\n return lower_key\n else:\n return search_lower(avl[root][2],key,lower_key)\n \n # == \n if avl[root][1] == None:\n return lower_key\n else:\n if lower_key == None:\n return end_higher(avl[root][1])\n else:\n return max(lower_key,end_higher[root][1])\n\n\n\ndef search_higher(root,key,higher_key):\n if avl[root][0] > key:\n higher_key = avl[root][0]\n if avl[root][1] == None:\n return higher_key\n else:\n return search_higher(avl[root][1],key,higher_key)\n if avl[root][0] < key:\n if avl[root][2] == None:\n return higher_key\n else:\n return search_higher(avl[root][2],key,higher_key)\n \n # == \n if avl[root][1] == None:\n return higher_key\n else:\n if higher_key == None:\n return end_lower(avl[root][1])\n else:\n return min(higher_key,end_lower[root][1])\n\n##search_less(0,x,None):O(logN)\n\ndef search_less(root,key,lower_key):\n if avl[root][0] > key:\n if avl[root][1] == None:\n return lower_key\n else:\n return search_less(avl[root][1],key,lower_key)\n if avl[root][0] < key:\n lower_key = avl[root][0]\n if avl[root][2] == None:\n return lower_key\n else:\n return search_less(avl[root][2],key,lower_key)\n \n # == \n return key\n\n##search_more(0,x,None):O(logN)\n\ndef search_more(root,key,higher_key):\n if avl[root][0] > key:\n higher_key = avl[root][0]\n if avl[root][1] == None:\n return higher_key\n else:\n return search_more(avl[root][1],key,higher_key)\n if avl[root][0] < key:\n if avl[root][2] == None:\n return higher_key\n else:\n return search_more(avl[root][2],key,higher_key)\n \n # == \n return key\n\n\n\ndef DoubleRightRotation(x):\n tl = avl[x][1]\n avl[x][1] = avl[avl[tl][2]][2]\n avl[avl[tl][2]][2] = x\n tlr = avl[tl][2]\n avl[tl][2] = avl[tlr][1]\n avl[tlr][1] = tl\n if balance[tlr] == -1:\n balance[avl[tlr][2]] = 1\n balance[avl[tlr][1]] = 0\n elif balance[tlr] == 1:\n balance[avl[tlr][2]] = 0\n balance[avl[tlr][1]] = -1\n else:\n balance[avl[tlr][2]] = 0\n balance[avl[tlr][1]] = 0\n balance[tlr] = 0\n return tlr\n\ndef DoubleLeftRotation(x):\n tr = avl[x][2]\n avl[x][2] = avl[avl[tr][1]][1]\n avl[avl[tr][1]][1] = x\n trl = avl[tl][1]\n avl[tr][1] = avl[trl][2]\n avl[trl][2] = tr\n if balance[trl] == 1:\n balance[avl[trl][2]] = 0\n balance[avl[trl][1]] = -1\n elif balance[trl] == -1:\n balance[avl[trl][1]] = 0\n balance[avl[trl][2]] = 1\n else:\n balance[avl[trl][2]] = 0\n balance[avl[trl][1]] = 0\n balance[trl] = 0\n return trl\n\ndef SingleLeftRotation(x):\n tr = avl[x][2]\n balance[tr] = 0\n balance[x] = 0\n avl[x][2] = avl[tr][1]\n avl[tr][1] = x\n return tr\n\ndef SingleRightRotaion(x):\n tl = avl[x][1]\n balance[tl] = 0\n balance[x] = 0\n avl[x][1] = avl[tl][2]\n avl[tl][2] = x\n return tl\n\ndef replace(x,p,v):\n if avl[p][1] == x:\n avl[p][1] = v\n else:\n avl[p][2] = v\n\ndef insertx(root,p,key):\n if avl[root][0] > key:\n if avl[root][1] == None:\n avl.append([key,None,None])\n avl[root][1] = len(avl)-1\n else:\n if not insertx(avl[root][1],root,key):\n return False\n if balance[root] == 1:\n balance[root] = 0\n return False\n elif balance[root] == 0:\n balance[root] = -1\n return True\n else:\n if balance[avl[root][1]] == 1:\n replace(root,p,DoubleRightRotation(root))\n elif balance[avl[root][1]] == -1:\n replace(root,p,SingleRightRotation(root))\n return False\n if avl[root][0] < key:\n if avl[root][2] == None:\n avl.append([key,None,None])\n avl[root][2] = len(avl)-1\n else:\n if not insertx(avl[root][2],root,key):\n return False\n if balance[root] == -1:\n balance[root] = 0\n return False\n elif balance[root] == 0:\n balance[root] = 1\n return True\n else:\n if balance[avl[root][2]] == -1:\n replace(root,p,DoubleLeftRotation(root))\n elif balance[avl[root][2]] == 1:\n replace(root,p,SingleLeftRotation(root))\n return False\n return False\n\n\n##insert(0,x):O(logN)\n\ndef insert(root,key):\n if key < avl[root][0]:\n if avl[root][1] == None:\n avl.append([key,None,None])\n avl[root][1] = len(avl)-1\n else:\n insertx(avl[root][1],root,key)\n elif key > avl[root][0]:\n if avl[root][2] == None:\n avl.append([key,None,None])\n avl[root][2] = len(avl)-1\n else:\n insertx(avl[root][2],root,key)\n else:\n pass\n\n########################################################\n\na,b,q = map(int,input().split())\ns = [int(input()) for i in range(a)]\n#avl[i]:[key,left_index,right_index]\n#balance[i]: {"Even":0,"Left":-1,"Right":1}\n\n#N_MAX = 1000000000\navl = [[s[0],None,None]]\nbalance = [0]*(a)\n\n\n#avl.append(first_avl)\n\nfor i in range(1,a):\n insert(0,s[i])\nprint(1)', 'class AVLTree(object):\n __slots__ = ["data", "left", "right", "bias", "size", "root"]\n\n def __init__(self, max_size):\n max_size += 1\n self.data = [0]*max_size\n self.left = [0]*max_size\n self.right = [0]*max_size\n self.bias = [0]*max_size\n self.size = 0\n self.root = 1\n\n def append_node(self, item):\n self.size += 1\n self.data[self.size] = item\n return self.size\n\n def __contains__(self, item) -> bool:\n data, left, right = self.data, self.left, self.right\n current = self.root\n while current:\n if data[current] == item:\n return True\n current = left[current] if item < data[current] else right[current]\n\n return False\n\n def search_lower(self, item):\n data, left, right = self.data, self.left, self.right\n current, result = self.root, None\n\n while current:\n if data[current] <= item:\n current, result = right[current], data[current]\n else:\n current = left[current]\n\n return result\n\n def search_higher(self, item):\n data, left, right = self.data, self.left, self.right\n current, result = self.root, None\n\n while current:\n if data[current] >= item:\n current, result = left[current], data[current]\n else:\n current = right[current]\n\n return result\n\n def insert(self, item) -> bool:\n left, right, bias, data = self.left, self.right, self.bias, self.data\n if not self.size:\n self.append_node(item)\n return True\n\n current, bias_delta = self.root, 0\n path = [(self.root, 0)]\n append_path, pop_path = path.append, path.pop\n\n while True:\n if data[current] == item:\n \n return False\n dest, bias_delta = (left, 1) if data[current] > item else (right, -1)\n\n if not dest[current]:\n dest[current] = self.append_node(item)\n break\n current = dest[current]\n append_path((current, bias_delta))\n\n while path:\n current, _delta = pop_path()\n bias[current] += bias_delta\n if not bias[current]:\n \n return True\n bias_delta = _delta\n\n if bias[current] == 2:\n current = self.rotate(current, left, right, 1, -1)\n break\n elif bias[current] == -2:\n current = self.rotate(current, right, left, -1, 1)\n break\n\n if path:\n (left if bias_delta > 0 else right)[path[-1][0]] = current\n else:\n self.root = current\n\n return True\n\n def rotate(self, parent: int, dir1, dir2, bias_type1, bias_type2) -> int:\n bias = self.bias\n child = dir1[parent]\n\n if bias[child] == bias_type1: # case 1\n dir2[child], dir1[parent] = parent, dir2[child]\n bias[parent] = bias[child] = 0\n return child\n\n # grandchild.left -> child.right, grandchild.right -> parent.left\n grandchild = dir2[child]\n dir2[child], dir1[parent] = dir1[grandchild], dir2[grandchild]\n dir1[grandchild], dir2[grandchild] = child, parent\n\n if bias[grandchild] == bias_type1: # case 2\n bias[parent], bias[child], bias[grandchild] = bias_type2, 0, 0\n elif bias[grandchild] == bias_type2: # case 3\n bias[parent], bias[child], bias[grandchild] = 0, bias_type1, 0\n else: # case 4\n bias[parent] = bias[child] = 0\n\n return grandchild\n\n def print(self):\n def rec(i, depth):\n if self.right[i]:\n rec(self.right[i], depth+1)\n print("{}+---[({}) bias={}]".format(" "*5*depth, self.data[i], self.bias[i]))\n if self.left[i]:\n rec(self.left[i], depth+1)\n\n rec(self.root, 0)\n print("="*30)\n\n\nif __name__ == "__main__":\n import sys\n A, B, Q = map(int, input().split())\n minf, inf = -(10**18), 10**18\n jinja_avl, tera_avl = AVLTree(A+2), AVLTree(B+2)\n jinja_insert, tera_insert = jinja_avl.insert, tera_avl.insert\n\n jsl, jsh = jinja_avl.search_lower, jinja_avl.search_higher\n tsl, tsh = tera_avl.search_lower, tera_avl.search_higher\n\n jinja_insert(minf)\n jinja_insert(inf)\n tera_insert(minf)\n tera_insert(inf)\n\n for n in map(int, (sys.stdin.readline() for _ in [0]*A)):\n jinja_insert(n)\n for n in map(int, (sys.stdin.readline() for _ in [0]*B)):\n tera_insert(n)\n ans = []\n append = ans.append\n\n for q in map(int, sys.stdin):\n left_jinja, right_jinja = q - jsl(q), jsh(q) - q\n left_tera, right_tera = q - tsl(q), tsh(q) - q\n\n append(min(\n left_jinja if left_jinja > left_tera else left_tera,\n left_jinja + right_tera + (left_jinja if left_jinja < right_tera else right_tera),\n right_jinja + left_tera + (right_jinja if right_jinja < left_tera else left_tera),\n right_jinja if right_jinja > right_tera else right_tera\n ))\n\n print(1)\n', 'import bisect\nimport sys\n\nclass Avltree:\n def __init__(self,key=None):\n self.key = key\n self.left = None\n self.right = None \n self.balance = "Even"\n def search(self,key):\n if self.key == None:\n return None\n if self.key > key:\n if self.left == None:\n return None\n else:\n return self.left.search(key)\n if self.key < key:\n if self.right == None:\n return None\n else:\n return self.right.search(key)\n return self \n \n def search_lower(self,key,key_lower):\n if self.key == None:\n return key_lower\n if self.key > key:\n if self.left == None:\n return key_lower\n else:\n return self.left.search_lower(key,key_lower)\n if self.key < key:\n key_lower = self.key\n if self.right == None:\n return key_lower\n else:\n return self.right.search_lower(key,key_lower)\n \n if self.left == None:\n return key_lower\n else:\n if key_lower == None:\n return self.left.end_higher(self.left.key)\n else:\n return max(key_lower,self.left.end_higher(self.left.key))\n \n def search_higher(self,key,key_higher):\n if self.key == None:\n return key_higher\n if self.key > key:\n key_higher = self.key\n if self.left == None:\n return key_higher\n else:\n return self.left.search_higher(key,key_higher)\n if self.key < key:\n if self.right == None:\n return key_higher\n else:\n return self.right.search_higher(key,key_higher)\n \n if self.right == None:\n return key_higher\n else:\n if key_higher == None:\n return self.right.end_lower(self.right.key)\n else:\n return min(key_higher,self.right.end_lower(self.right.key))\n \n \n def end_lower(self,end_lower_key):\n if self.left == None:\n return end_lower_key\n else:\n end_lower_key = self.left.key\n return self.left.end_lower(end_lower_key)\n def end_higher(self,end_higher_key):\n if self.right == None:\n return end_higher_key\n else:\n end_higher_key = self.right.key\n return self.right.end_higher(end_higher_key)\n \n \n def DoubleRightRotation(self):\n tl = self.left\n self.left = tl.right.right\n tl.right.right = self \n tlr = tl.right\n tl.right = tlr.left\n tlr.left = tl\n if tlr.balance == "Left":\n tlr.right.balance = "Right"\n tlr.left.balance = "Even"\n elif tlr.balance == "Right":\n tlr.right.balance = "Even"\n tlr.left.balance = "Left"\n elif tlr.balance == "Even":\n tlr.right.balance = "Even"\n tlr.left.balance = "Even"\n tlr.balance = "Even"\n return tlr\n def DoubleLeftRotation(self):\n tr = self.right\n self.right = tr.left.left\n tr.left.left = self\n trl = tr.left\n tr.left = trl.right\n trl.right = tr\n if trl.balance == "Right":\n trl.left.balance = "Left"\n trl.right.balance = "Even"\n elif trl.balance == "Left":\n trl.left.balance = "Even"\n trl.right.balance = "Right"\n elif trl.balance == "Even":\n trl.left.balance = "Even"\n trl.right.balance = "Even"\n trl.balance = "Even"\n return trl\n def SingleLeftRotation(self):\n tr = self.right\n tr.balance = "Even"\n self.balance = "Even"\n self.right = tr.left\n tr.left = self\n return tr\n def SingleRightRotation(self):\n tl = self.left\n tl.balance = "Even"\n self.balance = "Even"\n self.left = tl.right\n tl.right = self\n return tl\n def replace(self,p,v): \n if p.left == self:\n p.left = v\n else :\n p.right = v \n def insert(self,key): \n if self.key == None: \n self.key = key\n return self\n if key < self.key:\n if self.left == None:\n self.left = Avltree(key)\n else:\n self.left.insertx(self,key)\n elif key > self.key:\n if self.right == None:\n self.right = Avltree(key)\n else:\n self.right.insertx(self,key)\n else: # key == self.key:\n pass # do not overwrite\n def insertx(self,p,key): \n if self.key > key:\n if self.left == None:\n self.left = Avltree(key)\n else:\n if not self.left.insertx(self, key): \n return False \n if self.balance == "Right":\n self.balance = "Even"\n return False\n elif self.balance == "Even":\n self.balance = "Left"\n return True \n elif self.balance == "Left":\n if self.left.balance == "Right":\n self.replace(p,self.DoubleRightRotation())\n elif self.left.balance == "Left":\n self.replace(p,self.SingleRightRotation())\n return False \n if self.key < key:\n if self.right == None:\n self.right = Avltree(key)\n else:\n if not self.right.insertx(self, key):\n return False \n if self.balance == "Left":\n self.balance = "Even"\n return False\n elif self.balance == "Even":\n self.balance = "Right"\n return True\n elif self.balance == "Right":\n if self.right.balance == "Left": \n self.replace(p,self.DoubleLeftRotation())\n elif self.right.balance == "Right":\n self.replace(p,self.SingleLeftRotation())\n return False\n return False \n\n def to_s(self):\n return self.key\n def left_s(self):\n if self.left == None:\n return None\n return (self.left).key\n def right_s(self):\n if self.right == None:\n return None\n return (self.right).key\n \ninput = sys.stdin.readline\na, b, q = map(int,input().split())\ns = [int(input()) for i in range(a)]\nt = [int(input()) for i in range(b)]\nx = [int(input()) for i in range(q)]\nlens, lent = len(s), len(t)\ntreeA, treeB = Avltree(), Avltree()\nfor i in s: treeA.insert(i) \nfor i in t: treeB.insert(i)\nfor i in x:\n # atob\n p1,p2 = 0, 0\n alow = treeA.search_lower(i,10**15)\n ahigh = treeA.search_higher(i,10**15)\n p1 += abs(alow-i)\n p2 += abs(ahigh-i)\n p1 += min(abs(treeB.search_lower(alow,10**15)-alow),abs(treeB.search_higher(alow,10**15)-alow))\n p2 += min(abs(treeB.search_lower(ahigh,10**15)-ahigh),abs(treeB.search_higher(ahigh,10**15)-ahigh))\n ans = min(p1,p2)\n # print(p1,p2)\n \n p3,p4 = 0, 0\n blow = treeB.search_lower(i,10**15)\n bhigh = treeB.search_higher(i,10**15)\n p3 += abs(blow-i)\n p4 += abs(bhigh-i)\n p3 += min(abs(treeA.search_lower(blow,10**15)-blow),abs(treeA.search_higher(blow,10**15)-blow))\n p4 += min(abs(treeA.search_lower(bhigh,10**15)-bhigh),abs(treeA.search_higher(bhigh,10**15)-bhigh))\n ans = min(p3,p4,ans)\n # print(p3,p4)\n print(1)\n', 'import sys\nclass Bintree:\n def __init__(self,data=None): \n self.data = data\n self.left = None\n self.right = None\n def search(self,data):\n if self.data == None:\n return None\n if data < self.data:\n if self.left == None:\n return None \n else:\n return self.left.search(data) \n elif data > self.data:\n if self.right == None:\n return None\n else:\n return self.right.search(data)\n else: \n return self\n \n def insert(self,data):\n if self.data == None:\n self.data = data\n return self\n if data < self.data:\n if self.left == None:\n self.left = Bintree(data) \n return True\n else:\n return self.left.insert(data)\n elif data > self.data:\n if self.right == None:\n self.right = Bintree(data)\n return True\n else:\n return self.right.insert(data)\n else: # data == self.data:\n return False\n def to_s(self):\n return self.data\n def left_s(self):\n if self.left==None:\n return None\n return (self.left).data\n def right_s(self):\n if self.right == None:\n return None\n return (self.right).data\n \ninput = sys.stdin.readline\na, b, q = map(int,input().split())\ns = [int(input()) for i in range(a)]\nt = [int(input()) for i in range(b)]\nx = [int(input()) for i in range(q)]\nlens, lent = len(s), len(t)\ntreeA, treeB = Bintree(), Bintree()\nfor i in s: treeA.insert(i) \nfor i in t: treeB.insert(i)\nprint(1)', '#AVL\n\n##search(0,x):O(logN)\n\ndef search(root,key):\n if avl_key[root] > key:\n if avl_left[root] == None:\n return None\n else:\n return search(avl_left[root],key)\n if avl_key[root] < key:\n if avl_right[root] == None:\n return None\n else:\n return search(avl_right[root],key)\n return root\n\n\n##search_lower(0,x,None):O(logN)\n\ndef search_lower(root,key,lower_key):\n if avl_key[root] > key:\n if avl_left[root] == None:\n return lower_key\n else:\n return search_lower(avl_left[root],key,lower_key)\n if avl_key[root] < key:\n lower_key = avl_key[root]\n if avl_right[root] == None:\n return lower_key\n else:\n return search_lower(avl_right[root],key,lower_key)\n \n # == \n return key\n\n\n\ndef search_higher(root,key,higher_key):\n if avl_key[root] > key:\n higher_key = avl_key[root]\n if avl_left[root] == None:\n return higher_key\n else:\n return search_higher(avl_left[root],key,higher_key)\n if avl_key[root] < key:\n if avl_right[root] == None:\n return higher_key\n else:\n return search_higher(avl_right[root],key,higher_key)\n \n # == \n return key\n\n\n\n\ndef DoubleRightRotation(x):\n tl = avl_left[x]\n avl_left[x] = avl_right[avl_right[tl]]\n avl_right[avl_right[tl]] = x\n tlr = avl_right[tl]\n avl_right[tl] = avl_left[tlr]\n avl_left[tlr] = tl\n if balance[tlr] == -1:\n balance[avl_right[tlr]] = 1\n balance[avl_left[tlr]] = 0\n elif balance[tlr] == 1:\n balance[avl_right[tlr]] = 0\n balance[avl_left[tlr]] = -1\n else:\n balance[avl_right[tlr]] = 0\n balance[avl_left[tlr]] = 0\n balance[tlr] = 0\n return tlr\n\ndef DoubleLeftRotation(x):\n tr = avl_right[x]\n avl_right[x] = avl_left[avl_left[tr]]\n avl_left[avl_left[tr]] = x\n trl = avl_left[tl]\n avl_left[tr] = avl_right[trl]\n avl_right[trl] = tr\n if balance[trl] == 1:\n balance[avl_right[trl]] = 0\n balance[avl_left[trl]] = -1\n elif balance[trl] == -1:\n balance[avl_left[trl]] = 0\n balance[avl_right[trl]] = 1\n else:\n balance[avl_right[trl]] = 0\n balance[avl_left[trl]] = 0\n balance[trl] = 0\n return trl\n\ndef SingleLeftRotation(x):\n tr = avl_right[x]\n balance[tr] = 0\n balance[x] = 0\n avl_right[x] = avl_left[tr]\n avl_left[tr] = x\n return tr\n\ndef SingleRightRotaion(x):\n tl = avl_left[x]\n balance[tl] = 0\n balance[x] = 0\n avl_left[x] = avl_right[tl]\n avl_right[tl] = x\n return tl\n\ndef replace(x,p,v):\n if avl_left[p] == x:\n avl_left[p] = v\n else:\n avl_right[p] = v\n\ndef insertx(root,p,key):\n if avl_key[root] > key:\n if avl_left[root] == None:\n avl_key.append(key)\n avl_left[root] = len(avl_key)-1\n else:\n if not insertx(avl_left[root],root,key):\n return False\n if balance[root] == 1:\n balance[root] = 0\n return False\n elif balance[root] == 0:\n balance[root] = -1\n return True\n else:\n if balance[avl_left[root]] == 1:\n replace(root,p,DoubleRightRotation(root))\n elif balance[avl_left[root]] == -1:\n replace(root,p,SingleRightRotation(root))\n return False\n if avl_key[root] < key:\n if avl_right[root] == None:\n avl_key.append(key)\n avl_right[root] = len(avl_key)-1\n else:\n if not insertx(avl_right[root],root,key):\n return False\n if balance[root] == -1:\n balance[root] = 0\n return False\n elif balance[root] == 0:\n balance[root] = 1\n return True\n else:\n if balance[avl_right[root]] == -1:\n replace(root,p,DoubleLeftRotation(root))\n elif balance[avl_right[root]] == 1:\n replace(root,p,SingleLeftRotation(root))\n return False\n return False\n\n\n##insert(0,x):O(logN)\n\ndef insert(root,key):\n if key < avl_key[root]:\n if avl_left[root] == None:\n avl_key.append(key)\n avl_left[root] = len(avl_key)-1\n else:\n insertx(avl_left[root],root,key)\n elif key > avl_key[root]:\n if avl_right[root] == None:\n avl_key.append(key)\n avl_right[root] = len(avl_key)-1\n else:\n insertx(avl_right[root],root,key)\n else:\n pass\n\n########################################################\n\n\n\n#balance[i]: {"Even":0,"Left":-1,"Right":1}\n\n\na,b,q = map(int,input().split())\ns = [int(input()) for i in range(a)]\nt = [int(input()) for i in range(b)]\nx = [int(input()) for i in range(q)]\n\navl_key = [s[0]]\navl_left = [None]*(a+2)\navl_right = [None]*(a+2)\nbalance = [0]*(a+2)\nfor i in range(1,a):\n insert(0,s[i])\ninsert(0,float("inf"))\ninsert(0,-float("inf"))\n\nfor i in range(q):\n print(search_higher(0,x[i],None))\n print(search_lower(0,x[i],None))\n\navl_key = [t[0]]\navl_left = [None]*b\navl_right = [None]*b\nbalance = [0]*b\ninsert(0,float("inf"))\ninsert(0,-float("inf"))\nfor i in range(1,b):\n insert(0,t[i])\nfor i in range(q):\n print(search_higher(0,x[i],None))\n print(search_lower(0,x[i],None))\n', 'import sys\n \nclass Avltree:\n def __init__(self,key=None):\n self.key = key\n self.left = None\n self.right = None \n self.balance = "Even"\n def search(self,key):\n if self.key == None:\n return None\n if self.key > key:\n if self.left == None:\n return None\n else:\n return self.left.search(key)\n if self.key < key:\n if self.right == None:\n return None\n else:\n return self.right.search(key)\n return self \n \n def search_lower(self,key,key_lower):\n if self.key == None:\n return key_lower\n if self.key > key:\n if self.left == None:\n return key_lower\n else:\n return self.left.search_lower(key,key_lower)\n if self.key < key:\n key_lower = self.key\n if self.right == None:\n return key_lower\n else:\n return self.right.search_lower(key,key_lower)\n \n if self.left == None:\n return key_lower\n else:\n if key_lower == None:\n return self.left.end_higher(self.left.key)\n else:\n return max(key_lower,self.left.end_higher(self.left.key))\n \n def search_higher(self,key,key_higher):\n if self.key == None:\n return key_higher\n if self.key > key:\n key_higher = self.key\n if self.left == None:\n return key_higher\n else:\n return self.left.search_higher(key,key_higher)\n if self.key < key:\n if self.right == None:\n return key_higher\n else:\n return self.right.search_higher(key,key_higher)\n \n if self.right == None:\n return key_higher\n else:\n if key_higher == None:\n return self.right.end_lower(self.right.key)\n else:\n return min(key_higher,self.right.end_lower(self.right.key))\n \n \n def end_lower(self,end_lower_key):\n if self.left == None:\n return end_lower_key\n else:\n end_lower_key = self.left.key\n return self.left.end_lower(end_lower_key)\n def end_higher(self,end_higher_key):\n if self.right == None:\n return end_higher_key\n else:\n end_higher_key = self.right.key\n return self.right.end_higher(end_higher_key)\n \n \n def DoubleRightRotation(self):\n tl = self.left\n self.left = tl.right.right\n tl.right.right = self \n tlr = tl.right\n tl.right = tlr.left\n tlr.left = tl\n if tlr.balance == "Left":\n tlr.right.balance = "Right"\n tlr.left.balance = "Even"\n elif tlr.balance == "Right":\n tlr.right.balance = "Even"\n tlr.left.balance = "Left"\n elif tlr.balance == "Even":\n tlr.right.balance = "Even"\n tlr.left.balance = "Even"\n tlr.balance = "Even"\n return tlr\n def DoubleLeftRotation(self):\n tr = self.right\n self.right = tr.left.left\n tr.left.left = self\n trl = tr.left\n tr.left = trl.right\n trl.right = tr\n if trl.balance == "Right":\n trl.left.balance = "Left"\n trl.right.balance = "Even"\n elif trl.balance == "Left":\n trl.left.balance = "Even"\n trl.right.balance = "Right"\n elif trl.balance == "Even":\n trl.left.balance = "Even"\n trl.right.balance = "Even"\n trl.balance = "Even"\n return trl\n def SingleLeftRotation(self):\n tr = self.right\n tr.balance = "Even"\n self.balance = "Even"\n self.right = tr.left\n tr.left = self\n return tr\n def SingleRightRotation(self):\n tl = self.left\n tl.balance = "Even"\n self.balance = "Even"\n self.left = tl.right\n tl.right = self\n return tl\n def replace(self,p,v): \n if p.left == self:\n p.left = v\n else :\n p.right = v \n def insert(self,key): \n if self.key == None: \n self.key = key\n return self\n if key < self.key:\n if self.left == None:\n self.left = Avltree(key)\n else:\n self.left.insertx(self,key)\n elif key > self.key:\n if self.right == None:\n self.right = Avltree(key)\n else:\n self.right.insertx(self,key)\n else: # key == self.key:\n pass # do not overwrite\n def insertx(self,p,key): \n if self.key > key:\n if self.left == None:\n self.left = Avltree(key)\n else:\n if not self.left.insertx(self, key): \n return False \n if self.balance == "Right":\n self.balance = "Even"\n return False\n elif self.balance == "Even":\n self.balance = "Left"\n return True \n elif self.balance == "Left":\n if self.left.balance == "Right":\n self.replace(p,self.DoubleRightRotation())\n elif self.left.balance == "Left":\n self.replace(p,self.SingleRightRotation())\n return False \n if self.key < key:\n if self.right == None:\n self.right = Avltree(key)\n else:\n if not self.right.insertx(self, key):\n return False \n if self.balance == "Left":\n self.balance = "Even"\n return False\n elif self.balance == "Even":\n self.balance = "Right"\n return True\n elif self.balance == "Right":\n if self.right.balance == "Left": \n self.replace(p,self.DoubleLeftRotation())\n elif self.right.balance == "Right":\n self.replace(p,self.SingleLeftRotation())\n return False\n return False \n \n def to_s(self):\n return self.key\n def left_s(self):\n if self.left == None:\n return None\n return (self.left).key\n def right_s(self):\n if self.right == None:\n return None\n return (self.right).key\n \ninput = sys.stdin.readline\na, b, q = map(int,input().split())\ns = [int(input()) for i in range(a)]\ntreeA = Avltree()\nfor i in s: treeA.insert(i)\nprint(1)', 'import bisect\nimport sys\nclass Bintree:\n def __init__(self,data=None): \n self.data = data\n self.left = None\n self.right = None\n def search(self,data):\n if self.data == None:\n return None\n if data < self.data:\n if self.left == None:\n return None \n else:\n return self.left.search(data) \n elif data > self.data:\n if self.right == None:\n return None\n else:\n return self.right.search(data)\n else: \n return self\n \n def insert(self,data):\n if self.data == None:\n self.data = data\n return self\n if data < self.data:\n if self.left == None:\n self.left = Bintree(data) \n return True\n else:\n return self.left.insert(data)\n elif data > self.data:\n if self.right == None:\n self.right = Bintree(data)\n return True\n else:\n return self.right.insert(data)\n else: # data == self.data:\n return False\n def to_s(self):\n return self.data\n def left_s(self):\n if self.left==None:\n return None\n return (self.left).data\n def right_s(self):\n if self.right == None:\n return None\n return (self.right).data\n\ninput = sys.stdin.readline\na, b, q = map(int,input().split())\ns = [int(input()) for i in range(a)]\nt = [int(input()) for i in range(b)]\nx = [int(input()) for i in range(q)]\nlens, lent = len(s), len(t)\ntreeA, treeB = Bintree(), Bintree()\nfor i in s: treeA.insert(i) \nfor i in t: treeB.insert(i)\n', '#AVL\n\n##search(0,x):O(logN)\n\ndef search(root,key):\n if avl_key[root] > key:\n if avl_left[root] == None:\n return None\n else:\n return search(avl_left[root],key)\n if avl_key[root] < key:\n if avl_right[root] == None:\n return None\n else:\n return search(avl_right[root],key)\n return root\n\n\n\ndef end_lower(root):\n if avl_left[root] == None:\n return avl_key[root]\n else:\n return end_lower(avl_left[root])\n\ndef end_higher(root):\n if avl_right[root] == None:\n return avl_key[root]\n else:\n return end_higher(avl_right[root])\n\n\n##search_lower(0,x,None):O(logN)\n\ndef search_lower(root,key,lower_key):\n if avl_key[root] > key:\n if avl_left[root] == None:\n return lower_key\n else:\n return search_lower(avl_left[root],key,lower_key)\n if avl_key[root] < key:\n lower_key = avl_key[root]\n if avl_right[root] == None:\n return lower_key\n else:\n return search_lower(avl_right[root],key,lower_key)\n \n # == \n if avl_left[root] == None:\n return lower_key\n else:\n if lower_key == None:\n return end_higher(avl_left[root])\n else:\n return max(lower_key,end_higher(avl_left[root]))\n\n\n\ndef search_higher(root,key,higher_key):\n if avl_key[root] > key:\n higher_key = avl_key[root]\n if avl_left[root] == None:\n return higher_key\n else:\n return search_higher(avl_left[root],key,higher_key)\n if avl_key[root] < key:\n if avl_right[root] == None:\n return higher_key\n else:\n return search_higher(avl_right[root],key,higher_key)\n \n # == \n if avl_right[root] == None:\n return higher_key\n else:\n if higher_key == None:\n return end_lower(avl_right[root])\n else:\n return min(higher_key,end_lower(avl_right[root]))\n\n\n\n\ndef DoubleRightRotation(x):\n tl = avl_left[x]\n avl_left[x] = avl_right[avl_right[tl]]\n avl_right[avl_right[tl]] = x\n tlr = avl_right[tl]\n avl_right[tl] = avl_left[tlr]\n avl_left[tlr] = tl\n if balance[tlr] == -1:\n balance[avl_right[tlr]] = 1\n balance[avl_left[tlr]] = 0\n elif balance[tlr] == 1:\n balance[avl_right[tlr]] = 0\n balance[avl_left[tlr]] = -1\n else:\n balance[avl_right[tlr]] = 0\n balance[avl_left[tlr]] = 0\n balance[tlr] = 0\n return tlr\n\ndef DoubleLeftRotation(x):\n tr = avl_right[x]\n avl_right[x] = avl_left[avl_left[tr]]\n avl_left[avl_left[tr]] = x\n trl = avl_left[tl]\n avl_left[tr] = avl_right[trl]\n avl_right[trl] = tr\n if balance[trl] == 1:\n balance[avl_right[trl]] = 0\n balance[avl_left[trl]] = -1\n elif balance[trl] == -1:\n balance[avl_left[trl]] = 0\n balance[avl_right[trl]] = 1\n else:\n balance[avl_right[trl]] = 0\n balance[avl_left[trl]] = 0\n balance[trl] = 0\n return trl\n\ndef SingleLeftRotation(x):\n tr = avl_right[x]\n balance[tr] = 0\n balance[x] = 0\n avl_right[x] = avl_left[tr]\n avl_left[tr] = x\n return tr\n\ndef SingleRightRotaion(x):\n tl = avl_left[x]\n balance[tl] = 0\n balance[x] = 0\n avl_left[x] = avl_right[tl]\n avl_right[tl] = x\n return tl\n\ndef replace(x,p,v):\n if avl_left[p] == x:\n avl_left[p] = v\n else:\n avl_right[p] = v\n\ndef insertx(root,p,key):\n if avl_key[root] > key:\n if avl_left[root] == None:\n avl_key.append(key)\n avl_left[root] = len(avl_key)-1\n else:\n if not insertx(avl_left[root],root,key):\n return False\n if balance[root] == 1:\n balance[root] = 0\n return False\n elif balance[root] == 0:\n balance[root] = -1\n return True\n else:\n if balance[avl_left[root]] == 1:\n replace(root,p,DoubleRightRotation(root))\n elif balance[avl_left[root]] == -1:\n replace(root,p,SingleRightRotation(root))\n return False\n if avl_key[root] < key:\n if avl_right[root] == None:\n avl_key.append(key)\n avl_right[root] = len(avl_key)-1\n else:\n if not insertx(avl_right[root],root,key):\n return False\n if balance[root] == -1:\n balance[root] = 0\n return False\n elif balance[root] == 0:\n balance[root] = 1\n return True\n else:\n if balance[avl_right[root]] == -1:\n replace(root,p,DoubleLeftRotation(root))\n elif balance[avl_right[root]] == 1:\n replace(root,p,SingleLeftRotation(root))\n return False\n return False\n\n\n##insert(0,x):O(logN)\n\ndef insert(root,key):\n if key < avl_key[root]:\n if avl_left[root] == None:\n avl_key.append(key)\n avl_left[root] = len(avl_key)-1\n else:\n insertx(avl_left[root],root,key)\n elif key > avl_key[root]:\n if avl_right[root] == None:\n avl_key.append(key)\n avl_right[root] = len(avl_key)-1\n else:\n insertx(avl_right[root],root,key)\n else:\n pass\n\n########################################################\n\n\n\n#balance[i]: {"Even":0,"Left":-1,"Right":1}\n\n\na,b,q = map(int,input().split())\ns = int(input())\navl_key = [s]\navl_left = [None]*a\navl_right = [None]*a\nbalance = [0]*a\n\nfor i in range(1,a):\n s = int(input())\n insert(0,s)\nt = int(input())\navl_key = [t]\navl_left = [None]*b\navl_right = [None]*b\nbalance = [0]*b\nfor i in range(1,b):\n t = int(input())\n insert(0,t)\nprint(1)\n', '# ) .MMdMMM; .M#(,dM] .:\n# ) .M@d@d#Mb dMGMM(MN .:\n# ) dM1MCdbMM_ .M@MSN;dM- .:\n# ) .M#(#?d#(Mb.. ...............JMIMIMLdM] .:\n# ) ..M#?NHM# ?MMMMMMMMMH"""""""HMM@(Nad#(Mb .:\n\n# ) ..MMY` !qN; (J ?MMN, .:\n# ) (MMD` .MM@ .MM{ .WMN, .:\n# ) dM@` dMM% .MM} (MMm .:\n# ) .M#` dMN! .MM} ~(MMr .:\n# ) .MM: dM# .MM} ..JM# .:\n# ) `` .M@ dMF .MM} .~(M# ` . .:\n\n# ) dMr ?Mm, 7YYMM#!` .:\n# ) dMb ?` ., ` .. ~.(MM% .:\n# ) ..JgMMNNN) .Mn.(Mm-JM{ dHHMMNag., .:\n# ) ("! ?MN,.., (NM@"`~OMM} ..~-(M@` _?"M[ .:\n# ) ,MMM#_ .M# .M#` .~.~JMMMNg-.. .:\n\n# ) .gMB=` _7WMMNaJ... ....__-(JJgMMMM^ ?T"^ .:\n\n\n\n\nimport sys\nimport bisect\ninput = sys.stdin.readline\n\na,b,q = map(int,input().split())\ns = []\nt = []\nfor i in range(a):\n S = int(input())\n s.append(S)\nfor i in range(b):\n T = int(input())\n t.append(T)\ns.sort()\nt.sort()\n\ndef f(x):\n if 0<=x and a-1>= x:\n return True\n return False\ndef g(x):\n if 0<=x and b-1>= x:\n return True\n return False\nfor i in range(q):\n x = int(input())\n p = bisect.bisect_left(s,x)\n m = bisect.bisect_left(t,x)\n \n res = []\n if f(p) and g(m):\n res.append(max(t[m],s[p])-x)\n if f(p) and g(m-1):\n res.append(min(s[p]-x,x-t[m-1])+s[p]-t[m-1])\n if f(p-1) and g(m):\n res.append(t[m]-s[p-1]+min(t[m]-x,x-s[p-1]))\n if f(p-1) and g(m-1):\n res.append(x-min(t[m-1],s[p-1]))\n print(min(res))']
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s013796429', 's019177464', 's048560378', 's055119345', 's133682131', 's180359593', 's339838137', 's399288027', 's404465552', 's458142659', 's477514509', 's586416003', 's622249812', 's648755750', 's709629918', 's868095393', 's922473024', 's754536193']
[23484.0, 21260.0, 13532.0, 15680.0, 68960.0, 62944.0, 25364.0, 17364.0, 64992.0, 21256.0, 24928.0, 68968.0, 15968.0, 23136.0, 32980.0, 15980.0, 12640.0, 12212.0]
[2105.0, 889.0, 858.0, 2104.0, 2000.0, 2107.0, 1745.0, 1717.0, 1973.0, 900.0, 2105.0, 2116.0, 437.0, 2105.0, 926.0, 438.0, 1756.0, 887.0]
[5854, 7046, 6242, 3057, 7315, 7217, 7129, 6245, 7217, 7008, 5305, 8130, 1959, 5842, 7136, 1964, 6235, 3028]
p03112
u311636831
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['N = list(map(int, input().split()))\n#A = [[0] * (N[0]+N[1]+N[2])]*2\nA = [[10**10+1] * 4 for i in range((N[0]+N[1]+N[2]))]\n#print(A)\nfor i in range(N[0]):\n A[i][0]=int(input())\n A[i][1]=0\n\nfor i in range(N[0],N[0]+N[1]):\n A[i][0]=int(input())\n A[i][1]=1\n\nr=0\nfor i in range(N[0]+N[1],N[0]+N[1]+N[2]):\n A[i][0]=int(input())\n A[i][1]=2\n A[i][2]=r\n r+=1\n\nA=sorted(A)\n#print(A)\n\nL0=10**10+1\nR0=10**10+1\n\nL1=10**10+1\nR1=10**10+1\n\nj=0\n\nfor i in range(N[0]+N[1]+N[2]):\n k=i\n R0=10**10+1\n R1=10**10+1\n if(A[i][1]==0):L0=A[i][0]\n if(A[i][1]==1):L1=A[i][0]\n if(A[i][1]==2):\n for j in range(k,N[0]+N[1]+N[2]):\n if(A[j][1]==0):\n R0=A[j][0]\n if(A[j][1]==1):\n R1=A[j][0]\n if((R0!=(10**10+1))&(R1!=(10**10+1))):break\n LA01=abs(L0-A[i][0])\n RA01=abs(R0-A[i][0])\n LA11=abs(L1-A[i][0])\n RA11=abs(R1-A[i][0])\n LA02=LA01*2\n RA02=RA01*2\n LA12=LA11*2\n RA12=RA11*2\n\n #print(min(max(LA01,LA11),LA01+RA12,RA01+LA12,max(RA01,RA11),max(LA01,LA11),LA02+RA11,RA02+LA11,max(RA01,RA11)))\n A[i][3]=min(max(LA01,LA11),LA01+RA12,RA01+LA12,max(RA01,RA11),max(LA01,LA11),LA02+RA11,RA02+LA11,max(RA01,RA11))\n\nA=sorted(A, key=lambda x: x[2])\n\nfor i in range(N[2]):\n print(A[i][3])\n\n', 'N = list(map(int, input().split()))\n#A = [[0] * (N[0]+N[1]+N[2])]*2\nA = [[10**11+1] * 4 for i in range((N[0]+N[1]+N[2]))]\n#print(A)\nfor i in range(N[0]):\n A[i][0]=int(input())\n A[i][1]=0\n\nfor i in range(N[0],N[0]+N[1]):\n A[i][0]=int(input())\n A[i][1]=1\n\nr=0\nfor i in range(N[0]+N[1],N[0]+N[1]+N[2]):\n A[i][0]=int(input())\n A[i][1]=2\n A[i][2]=r\n r+=1\n\nA=sorted(A)\n#print(A)\n\nL0=10**11+1\nR0=10**11+1\n\nL1=10**11+1\nR1=10**11+1\n\nj=0\n\nfor i in range(N[0]+N[1]+N[2]):\n k=i\n R0=10**11+1\n R1=10**11+1\n if(A[i][1]==0):L0=A[i][0]\n if(A[i][1]==1):L1=A[i][0]\n if(A[i][1]==2):\n for j in range(k,N[0]+N[1]+N[2]):\n if(A[j][1]==0):\n R0=A[j][0]\n if(A[j][1]==1):\n R1=A[j][0]\n if((R0!=(10**11+1))&(R1!=(10**11+1))):break\n LA01=abs(L0-A[i][0])\n RA01=abs(R0-A[i][0])\n LA11=abs(L1-A[i][0])\n RA11=abs(R1-A[i][0])\n LA02=LA01*2\n RA02=RA01*2\n LA12=LA11*2\n RA12=RA11*2\n\n #print(min(max(LA01,LA11),LA01+RA12,RA01+LA12,max(RA01,RA11),max(LA01,LA11),LA02+RA11,RA02+LA11,max(RA01,RA11)))\n A[i][3]=min(max(LA01,LA11),LA01+RA12,RA01+LA12,max(RA01,RA11),max(LA01,LA11),LA02+RA11,RA02+LA11,max(RA01,RA11))\n\nA=sorted(A, key=lambda x: x[2])\n\nfor i in range(N[2]):\n print(A[i][3])\n\n', 'import math\nimport bisect\nA,B,Q = list(map(int,input().split(" ")))\nSs = [int(input())for _ in range(A)]\nTs = [int(input())for _ in range(B)]\nXs = [int(input())for _ in range(Q)]\nSs.sort()\nTs.sort()\nss = len(Ss)\nts = len(Ts)\nfor x in Xs:\n si = bisect.bisect_right(Ss,x)\n ti = bisect.bisect_right(Ts,x)\n\n cands = [[],[]]\n if si > 0:\n cands[0].append(Ss[si-1])\n if si < ss:\n cands[0].append(Ss[si])\n if ti > 0:\n cands[1].append(Ts[ti-1])\n if ti < ts:\n cands[1].append(Ts[ti])\n \n anss = []\n temp = 0\n for i in [0,1]:\n for t1 in cands[i]: \n for t2 in cands[1-i]: \n temp = abs(x-t1) + abs(t2-t1)\n anss.append(temp)\n print(min(anss))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s305890035', 's337280569', 's976562963']
[60032.0, 59836.0, 16168.0]
[2108.0, 2108.0, 1272.0]
[1328, 1328, 772]
p03112
u316386814
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nA, B, Q = list(map(int, input().split()))\nS, T, X = [-INF], [-INF], []\nfor _ in range(A):\n S.append(int(input()))\nfor _ in range(B):\n T.append(int(input()))\nfor _ in range(Q):\n X.append(int(input()))\nINF = 10 ** 12\nS.append(INF)\nT.append(INF)\n\nfor x in X:\n ans = INF\n sr = bisect.bisect_right(S, x)\n tr = bisect.bisect_right(T, x)\n for s in S[sr-1: sr+1]:\n for t in T[tr-1: tr+1]:\n ans = min(ans, abs(s-x) + abs(s-t), abs(t-x) + abs(s-t))\n print(ans)\n', 'import bisect\nINF = 10 ** 12\n\nA, B, Q = list(map(int, input().split()))\nS, T, X = [-INF], [-INF], []\nfor _ in range(A):\n S.append(int(input()))\nfor _ in range(B):\n T.append(int(input()))\nfor _ in range(Q):\n X.append(int(input()))\nS.append(INF)\nT.append(INF)\n\nfor x in X:\n ans = INF\n sr = bisect.bisect_right(S, x)\n tr = bisect.bisect_right(T, x)\n for s in S[sr-1: sr+1]:\n for t in T[tr-1: tr+1]:\n ans = min(ans, abs(s-x) + abs(s-t), abs(t-x) + abs(s-t))\n print(ans)\n']
['Runtime Error', 'Accepted']
['s177015236', 's128196131']
[3064.0, 16160.0]
[17.0, 1146.0]
[507, 508]
p03112
u319818856
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = min(bisect.bisect_right(s, x), A-1), min(bisect.bisect_right(t, x), B-1)\n a, c = max(b-1, 0), max(d-1, 0)\n \n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n \t res = min(res, d1, d2)\n \t print(res)', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n \tres = min(res, d1, d2)\n \tprint(res)', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n a, c = max(b-1, 0), max(d-1, 0)\n\n res = INF\n print(a, b, c, d)\n for S in s[b-1:b+1]:\n for T in t[d-1:d+1]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)\n', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = min(bisect.bisect_right(s, x), A+1), \\\n min(bisect.bisect_right(t, x), B+1)\n a, c = max(b-1, 0), max(d-1, 0)\n\n res = INF\n print(a, b, c, d)\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)\n', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n \t res = min(res, d1, d2)\n \t print(res)', 'A, B, Q = [int(s) for s in input().split()]\n\n\nshrines = []\ntemples = []\n\nfor _ in range(A):\n s = int(input())\n shrines.append((s, 10**10))\n\n\n\nji = 0\nfor _ in range(B):\n tp, tc = int(input()), 10**10\n sp, sc = shrines[ji]\n\n while abs(tp - sp) < tc:\n tc = abs(tp - sp)\n\n if abs(tp - sp) < sc:\n shrines[ji] = (sp, abs(tp - sp))\n\n if ji + 1 < A:\n ji += 1\n sp, sc = shrines[ji]\n else:\n break\n\n temples.append((tp, tc))\n\nroad = sorted(temples + shrines, key=lambda x: x[0])\n\n\ndef search(x):\n global A, B\n\n l, r = 0, A + B\n while r - l > 1:\n m = (l + r) // 2\n mp, mc = road[m]\n\n if mp < x:\n l = m\n else:\n r = m\n\n p1, c1 = road[l]\n if l == A + B - 1 or A + B == 1:\n return abs(x - p1) + c1\n\n p2, c2 = road[l+1]\n return min(abs(x-p1) + c1, abs(x-p2) + c2)\n\n\nfor _ in range(Q):\n q = int(input())\n\n y = search(q)\n print(q, y)\n', 'A, B, Q = [int(s) for s in input().split()]\n\n\nshrines = []\ntemples = []\n\nfor _ in range(A):\n s = int(input())\n shrines.append((s, 10**10))\n\n\n\nji = 0\nfor _ in range(B):\n tp, tc = int(input()), 10**10\n sp, sc = shrines[ji]\n\n while abs(tp - sp) < tc:\n tc = abs(tp - sp)\n\n if abs(tp - sp) < sc:\n shrines[ji] = (sp, abs(tp - sp))\n\n if ji + 1 < A:\n ji += 1\n sp, sc = shrines[ji]\n else:\n break\n\n temples.append((tp, tc))\n\nroad = sorted(temples + shrines, key=lambda x: x[0])\n\n\ndef search(x):\n global A, B\n\n l, r = 0, A + B\n while r - l > 1:\n m = (l + r) // 2\n mp, mc = road[m]\n\n if mp < x:\n l = m\n else:\n r = m\n\n p1, c1 = road[l]\n if l == A + B - 1 or A + B == 1:\n return abs(x - p1) + c1\n\n p2, c2 = road[l+1]\n return min(abs(x-p1) + c1, abs(x-p2) + c2)\n\n\nfor _ in range(Q):\n q = int(input())\n\n y = search(q)\n print(q, y)\n', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n\n res = INF\n for S in s[b-1:b+1]:\n for T in t[d-1:d+1]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s205704382', 's233949349', 's246140175', 's328410480', 's365910459', 's409882131', 's637701550', 's888707448', 's554191322']
[3064.0, 3064.0, 3064.0, 15364.0, 15104.0, 3064.0, 36356.0, 36356.0, 13952.0]
[17.0, 17.0, 17.0, 2031.0, 2068.0, 17.0, 1996.0, 2049.0, 1754.0]
[509, 446, 440, 524, 566, 452, 1138, 1138, 466]
p03112
u325227960
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import numpy as np\n\na,b,q=map(int,input().split())\n\nST=[]\nfor i in range(a):\n k=int(input())\n ST.append([k,0,0])\nfor i in range(b):\n k=int(input())\n ST.append([k,1,0])\n\nST.sort()\n\nle0=-1\nle1=-1\nri0=1\nri1=1\n\nfor i in range(a+b):\n if ST[i][1]==0 :\n pa=1\n \n moyori=np.inf\n\n if le1>=0:\n moyori=min(moyori,abs(ST[i][0]-ST[le1][0]))\n if ri1<=i :\n ri1=i+1\n while ri1<=a+b-1 and ST[ri1][1]==ty :\n ri1+=1\n if ri1<=a+b-1:\n moyori=min(moyori,abs(ST[i][0]-ST[ri1][0]))\n ST[i][2]=moyori\n le0=i\n else:\n pa=0\n \n moyori=np.inf\n\n if le0>=0:\n moyori=min(moyori,abs(ST[i][0]-ST[le0][0]))\n if ri0<=i :\n ri0=i+1\n while ri0<=a+b-1 and ST[ri0][1]==ty :\n ri0+=1\n if ri0<=a+b-1:\n moyori=min(moyori,abs(ST[i][0]-ST[ri0][0]))\n ST[i][2]=moyori\n le1=i\n\n\n\n#print(ST)\n\nfor i in range(q):\n k=int(input())\n ST.append([k,2,0,i])\n\nST.sort()\n\nANS=[]\nle0=-1\nle1=-1\nri0=1\nri1=1\nfor i in range(a+b+q):\n if ST[i][1]==0 :\n le0=i\n elif ST[i][1]==1 :\n le1=i\n elif ST[i][1]==2 :\n moyori=np.inf\n \n \n if le0>=0:\n moyori=min(moyori,abs(ST[i][0]-ST[le0][0])+ST[le0][2])\n #print("L"+str(le[typ]))\n \n if ri0<=i :\n ri0=i+1\n while ri0<=a+b+q-1 and (ST[ri0][1]==1 or ST[ri0][1]==2):\n ri0+=1\n if ri0<=a+b+q-1 :\n moyori=min(moyori,abs(ST[i][0]-ST[ri0][0])+ST[ri0][2])\n #print("R"+str(ri[typ]))\n \n\n if le1>=0:\n moyori=min(moyori,abs(ST[i][0]-ST[le1][0])+ST[le1][2])\n #print("L"+str(le[typ]))\n \n if ri1<=i :\n ri1=i+1\n while ri1<=a+b+q-1 and (ST[ri1][1]==0 or ST[ri1][1]==2):\n ri1+=1\n if ri1<=a+b+q-1 :\n moyori=min(moyori,abs(ST[i][0]-ST[ri1][0])+ST[ri1][2])\n #print("R"+str(ri[typ]))\n \n\n\n\n ST[i][2]=moyori\n ANS.append([ST[i][3],moyori])\n\nANS.sort()\n\n#print(ST)\n\nfor i in range(q):\n print(ANS[i][1])\n', 'import bisect as bi\n\na,b,q=map(int,input().split())\n\nINF=10**15\n\nS=[-INF]+[int(input()) for i in range(a)]+[INF]\nT=[-INF]+[int(input()) for i in range(b)]+[INF]\nX=[int(input()) for i in range(q)]\n\nfor i in range(q):\n d=bi.bisect_right(S,X[i])\n e=bi.bisect_right(T,X[i])\n as0=abs(X[i]-S[d-1])\n as1=abs(X[i]-S[d])\n at0=abs(X[i]-T[e-1])\n at1=abs(X[i]-T[e])\n ans=min(max(as0,at0),max(as1,at1),2*as0+at1,as0+2*at1,2*at0+as1,at0+as1*2)\n print(ans)\n']
['Runtime Error', 'Accepted']
['s700715982', 's462689705']
[39568.0, 17552.0]
[617.0, 964.0]
[2261, 466]
p03112
u326609687
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['A, B, Q = map(int, input().split())\ns = [-10**10] + [int(input()) for _ in range(A)] + [2*10**10, 2*10**10 + 1]\nt = [-10**10] + [int(input()) for _ in range(B)] + [2*10**10, 2*10**10 + 1]\nx = [int(input()) for _ in range(Q)]\n\n\ndef searchindex(p, z):\n for i, d in enumerate(p):\n if d > z:\n return i - 1\n\n\ndef func(c, d, z):\n i = searchindex(c, z)\n j1 = searchindex(d, c[i])\n j2 = searchindex(d, c[i + 1])\n return min(z - d[j1], z - c[i] * 2 + d[j1 + 1], d[j2 + 1] - z, c[i + 1] * 2 - z - d[j2])\n\n\nans = []\nfor z in x:\n ans.append(min(func(s, t, z), func(t, s, z)))\n\nprint(ans)', 'import bisect\nA, B, Q = map(int, input().split())\ns = [-10**10 - 1, -10**10] + [int(input()) for _ in range(A)] + [2*10**10]\nt = [-10**10 - 1, -10**10] + [int(input()) for _ in range(B)] + [2*10**10]\nx = [int(input()) for _ in range(Q)]\n\n\ndef func(c, d, z):\n i = bisect.bisect_left(c, z)\n j = bisect.bisect_left(d, z)\n if c[i - 1] < d[j - 1] and c[i] < d[j]:\n return min(z - c[i - 1], z + c[i] - 2 * d[j - 1], 2 * c[i] - z - d[j - 1], d[j] - z)\n elif c[i - 1] < d[j - 1] and c[i] > d[j]:\n return min(z - c[i - 1], z + c[i] - 2 * d[j - 1], 2 * d[j] - z - c[i - 1], c[i] - z)\n elif c[i - 1] > d[j - 1] and c[i] < d[j]:\n return min(z - d[j - 1], z + d[j] - 2 * c[i - 1], 2 * c[i] - z - d[j - 1], d[j] - z)\n else:\n return min(z - d[j - 1], z + d[j] - 2 * c[i - 1], 2 * d[j] - z - c[i - 1], c[i] - z)\n\n\nfor z in x:\n print(func(s, t, z))\n', 'import bisect\nA, B, Q = map(int, input().split())\ns = [-10**10 - 1, -10**10] + [int(input()) for _ in range(A)] + [2*10**10]\nt = [-10**10 - 1, -10**10] + [int(input()) for _ in range(B)] + [2*10**10]\nx = [int(input()) for _ in range(Q)]\n\n\ndef func(c, d, z):\n i = bisect.bisect_left(c, z)\n j = bisect.bisect_left(d, z)\n if c[i - 1] < d[j - 1] and c[i] < d[j]:\n return min(z - c[i - 1], z + c[i] - 2 * d[j - 1], 2 * c[i] - z - d[j - 1], d[j] - z)\n elif c[i - 1] < d[j - 1] and c[i] >= d[j]:\n return min(z - c[i - 1], z + c[i] - 2 * d[j - 1], 2 * d[j] - z - c[i - 1], c[i] - z)\n elif c[i - 1] >= d[j - 1] and c[i] < d[j]:\n return min(z - d[j - 1], z + d[j] - 2 * c[i - 1], 2 * c[i] - z - d[j - 1], d[j] - z)\n else:\n return min(z - d[j - 1], z + d[j] - 2 * c[i - 1], 2 * d[j] - z - c[i - 1], c[i] - z)\n\n\nfor z in x:\n print(func(s, t, z))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s423982152', 's698505981', 's676551075']
[14848.0, 16152.0, 16152.0]
[2104.0, 911.0, 839.0]
[611, 881, 882]
p03112
u343523393
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n\tx = int(input())\n\tb, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n\tres = INF\n\tfor S in [s[b - 1], s[b]]:\n\t\tfor T in [t[d - 1], t[d]]:\n\t\td1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n\tres = min(res, d1, d2)\n\tprint(res)', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)']
['Runtime Error', 'Accepted']
['s678521070', 's978921370']
[3064.0, 13972.0]
[18.0, 1713.0]
[434, 476]
p03112
u346308892
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['\nimport numpy as np\nfrom functools import *\nimport sys\nsys.setrecursionlimit(100000)\n\n\ndef acinput():\n return list(map(int, input().split(" ")))\n\n\ndef II():\n return int(input())\n\nmod = 10**9+7\n\n\ndef factorial(n):\n fact = 1\n for integer in range(1, n + 1):\n fact *= integer\n return fact\n\n\n\ndef serch(x, count):\n #print("top", x, count)\n \n\n for d in directions:\n nx = d+x\n #print(nx)\n if np.all(0 <= nx) and np.all(nx < (H, W)):\n if field[nx[0]][nx[1]] == "E":\n count += 1 \n field[nx[0]][nx[1]] = "V"\n count = serch(nx, count) \n continue\n if field[nx[0]][nx[1]] == "#":\n field[nx[0]][nx[1]] = "V"\n count = serch(nx, count) \n \n return count\n\na,b,q=acinput()\n\nS=[]\nfor i in range(a):\n S.append(II())\n\nT=[]\nfor i in range(b):\n T.append(II())\n\nX=[II() for i in range(q)]\n\nimport bisect\n\nfor i in range(q):\n x=X[i]\n\n t=bisect.bisect(S,x)\n t=min(t,a-1)\n d1=abs(S[t]-x)\n t2=bisect.bisect(T,S[t])\n t2=min(t2,b-1)\n d2=abs(T[t2]-S[t])\n\n res=d1+d2\n\n t = bisect.bisect(T, x)\n t = min(t, b-1)\n d1 = abs(T[t]-x)\n t2 = bisect.bisect(S,T[t])\n t2 = min(t2, a-1)\n d2 = abs(S[t2]-T[t])\n res=min(res,d1+d2)\n print(res)\n\n\n\n\n\n\n', '\nimport numpy as np\nfrom functools import *\nimport sys\nsys.setrecursionlimit(100000)\n\n\ndef acinput():\n return list(map(int, input().split(" ")))\n\n\ndef II():\n return int(input())\n\nmod = 10**9+7\n\n\ndef factorial(n):\n fact = 1\n for integer in range(1, n + 1):\n fact *= integer\n return fact\n\n\n\ndef serch(x, count):\n #print("top", x, count)\n \n\n for d in directions:\n nx = d+x\n #print(nx)\n if np.all(0 <= nx) and np.all(nx < (H, W)):\n if field[nx[0]][nx[1]] == "E":\n count += 1 \n field[nx[0]][nx[1]] = "V"\n count = serch(nx, count) \n continue\n if field[nx[0]][nx[1]] == "#":\n field[nx[0]][nx[1]] = "V"\n count = serch(nx, count) \n \n return count\n\na,b,q=acinput()\n\nS=[]\nfor i in range(a):\n S.append(II())\n\nT=[]\nfor i in range(b):\n T.append(II())\n\n\n\nimport bisect\n\nfor i in range(q):\n x=II()\n\n t=bisect.bisect(S,x)\n t=min(t,a-1)\n d1=abs(S[t]-x)\n t2=bisect.bisect(T,S[t])\n t2=min(t2,b-1)\n d2=abs(T[t2]-S[t])\n\n res=d1+d2\n\n t = bisect.bisect(T, x)\n t = min(t, b-1)\n d1 = abs(T[t]-x)\n t2 = bisect.bisect(S,T[t])\n t2 = min(t2, a-1)\n d2 = abs(S[t2]-T[t])\n res=min(res,d1+d2)\n print(res)\n\n\n\n\n\n\n', '\nimport numpy as np\nfrom functools import *\nimport sys\nsys.setrecursionlimit(100000)\n\n\ndef acinput():\n return list(map(int, input().split(" ")))\n\n\ndef II():\n return int(input())\n\nmod = 10**9+7\n\n\ndef factorial(n):\n fact = 1\n for integer in range(1, n + 1):\n fact *= integer\n return fact\n\n\n\ndef serch(x, count):\n #print("top", x, count)\n \n\n for d in directions:\n nx = d+x\n #print(nx)\n if np.all(0 <= nx) and np.all(nx < (H, W)):\n if field[nx[0]][nx[1]] == "E":\n count += 1 \n field[nx[0]][nx[1]] = "V"\n count = serch(nx, count) \n continue\n if field[nx[0]][nx[1]] == "#":\n field[nx[0]][nx[1]] = "V"\n count = serch(nx, count) \n \n return count\n\na,b,q=acinput()\n\nS=[]\nfor i in range(a):\n S.append(II())\n\nT=[]\nfor i in range(b):\n T.append(II())\n\nX=[II() for i in range(q)]\n\nimport bisect\n\n\ndef near(arr,v):\n t=bisect.bisect(arr,v)\n\n \n if t>=len(arr)-1:\n return len(arr)-1\n if t==0:\n return 0\n #print(t)\n t-=1\n m = (abs(arr[t]-v) > abs(arr[t+1]-v))\n res = t+m\n #print(arr, v, res,m)\n return res\n\n\n\nfor i in range(q):\n x=X[i]\n\n s=near(S,x)\n t=near(T,S[s])\n res1=abs(S[s]-x)+abs(T[t]-S[s])\n\n t = near(T, x)\n s = near(S, T[t])\n res2 = abs(T[t]-x)+abs(T[t]-S[s])\n\n print(min(res1,res2))\n\n\n', '\nimport numpy as np\nfrom functools import *\nimport sys\nsys.setrecursionlimit(100000)\n\n\ndef acinput():\n return list(map(int, input().split(" ")))\n\n\ndef II():\n return int(input())\n\nmod = 10**9+7\n\n\ndef factorial(n):\n fact = 1\n for integer in range(1, n + 1):\n fact *= integer\n return fact\n\n\n\ndef serch(x, count):\n #print("top", x, count)\n \n\n for d in directions:\n nx = d+x\n #print(nx)\n if np.all(0 <= nx) and np.all(nx < (H, W)):\n if field[nx[0]][nx[1]] == "E":\n count += 1 \n field[nx[0]][nx[1]] = "V"\n count = serch(nx, count) \n continue\n if field[nx[0]][nx[1]] == "#":\n field[nx[0]][nx[1]] = "V"\n count = serch(nx, count) \n \n return count\n\na,b,q=acinput()\n\nS=[]\nfor i in range(a):\n S.append(II())\n\nT=[]\nfor i in range(b):\n T.append(II())\n\nX=[II() for i in range(q)]\n\nimport bisect\n\n\ndef near(arr,v):\n t=bisect.bisect_right(arr,v)\n\n #print(arr,t,v)\n if t==len(arr):\n return len(arr)-1\n t-=1\n t=max(t,0)\n return t+(abs(arr[t]-v)<abs(arr[t]-v))\n\n\n\nfor i in range(q):\n x=X[i]\n\n s=near(S,x)\n t=near(T,S[s])\n res1=abs(S[s]-x)+abs(T[t]-S[s])\n\n t = near(T, x)\n s = near(S, T[t])\n res2 = abs(T[t]-x)+abs(T[t]-S[s])\n\n print(min(res1,res2))\n\n\n', '\nimport numpy as np\nfrom functools import *\nimport sys\nsys.setrecursionlimit(100000)\n\n\ndef acinput():\n return list(map(int, input().split(" ")))\n\n\ndef II():\n return int(input())\n\nmod = 10**9+7\n\n\ndef factorial(n):\n fact = 1\n for integer in range(1, n + 1):\n fact *= integer\n return fact\n\n\na,b,q=acinput()\n\nS=[-10**15]\nfor i in range(a):\n S.append(II())\nS.append(10**15)\n\nT=[-10**15]\nfor i in range(b):\n T.append(II())\nT.append(10**15)\nX=[II() for i in range(q)]\n\nimport bisect\n\n\ndef near(arr,v):\n t=bisect.bisect(arr,v)\n \n #print(arr,v,t)\n if t>len(arr)-1:\n return len(arr)-1\n if t==0:\n return 0\n\n m = (abs(arr[t-1]-v) > abs(arr[t]-v))\n res = t+m-1\n #print(arr, v, res,m)\n return res\n\n\n#print(S)\nfor i in range(q):\n x=X[i]\n\n s=bisect.bisect_right(S,x)\n t = bisect.bisect_right(T, x)\n res=10**19\n for ss in [S[s-1],S[s]]:\n for tt in [T[t-1],T[t]]:\n tmp=abs(ss-x)+abs(ss-tt) \n res=min(res,tmp)\n tmp = abs(tt-x)+abs(ss-tt)\n res = min(res, tmp)\n print(res)\n\n\n']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s423599080', 's648904322', 's745297446', 's754731512', 's368287698']
[26332.0, 22752.0, 26736.0, 25328.0, 26704.0]
[1285.0, 1846.0, 1370.0, 1398.0, 1508.0]
[1352, 1353, 1444, 1381, 1103]
p03112
u350049649
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\n\nA,B,Q=map(int,input().split())\ns=[int(input()) for _ in range(A)]\nt=[int(input()) for _ in range(B)]\nq=[int(input()) for _ in range(Q)]\n\ndef solve(start):\n ans=[]\n x=bisect.bisect_left(s,start,lo=0,hi=len(s))\n\n t1=bisect.bisect_left(t,x,lo=0,hi=len(t))\n if x<len(s) and t1<len(t):\n ans.append(min(abs(start-s[x])+abs(t[t1]-s[x]),abs(start-s[x])+abs(t[t1-1]-s[x])))\n\n if x>=1:\n t2=bisect.bisect_left(t,x-1,lo=0,hi=len(t))\n ans.append(min(abs(start-s[x-1])+abs(t[t2]-s[x-1]),abs(start-s[x-1])+abs(t[t2-1]-s[x-1])))\n\n\n\n\n y=bisect.bisect_left(t,start,lo=0,hi=len(t))\n s1=bisect.bisect_left(s,x,lo=0,hi=len(s))\n if y < len(t) and s1 < len(s):\n ans.append(min(abs(start - t[y]) + abs(s[s1] - t[y]), abs(start - t[y]) + abs(s[s1 - 1] - t[y])))\n if y>=1:\n s2=bisect.bisect_left(s,y-1,lo=0,hi=len(s))\n ans.append(min(abs(start-t[y-1])+abs(s[s2]-t[y-1]),abs(start-t[y-1])+abs(t[s2-1]-t[y-1])))\n \n print(min(ans))\n\nfor e in q:\n solve(e)', 'import bisect\n\nA,B,Q=map(int,input().split())\nINF=10**18\ns=[-INF]+[int(input()) for _ in range(A)]+[INF]\nt=[-INF]+[int(input()) for _ in range(B)]+[INF]\nq=[int(input()) for _ in range(Q)]\n\ndef solve(start):\n ans=[]\n c,d=bisect.bisect_left(s,start),bisect.bisect_left(t,start)\n for S in [s[c],s[c-1]]:\n for T in [t[d],t[d-1]]:\n ans.append(min(abs(start-S)+abs(S-T),abs(start-T)+abs(S-T)))\n\n print(min(ans))\n\nfor e in q:\n solve(e)']
['Wrong Answer', 'Accepted']
['s378743172', 's278041804']
[16196.0, 16128.0]
[1898.0, 1073.0]
[1018, 461]
p03112
u350697094
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nA, B, Q = map(int, input().split())\ns = [int(input()) for i in range(A)]\nt = [int(input()) for i in range(B)]\nx = [int(input()) for i in range(Q)]\ninf = [10**13, -10**13]\nA,B,C=2, 3, 4\ns = sorted([100,600]+inf)\nt = sorted([400,900,1000]+inf)\nx = [150,2000,899,799]\n\nfor i in x:\n s_r = s[bisect.bisect_right(s, x[i])]\n s_l = s[bisect.bisect_left(s, x[i])-1]\n t_r = t[bisect.bisect_right(t, x[i])]\n t_l = t[bisect.bisect_left(t, x[i])-1]\n long = sorted([abs(t_r-s_r)+s_r-x[i], abs(t_l-s_r)+s_r-x[i], abs(t_l-s_l)+x[i]-s_l, abs(t_r-s_l)+x[i]-s_l,\n abs(s_r-t_r)+t_r-x[i], abs(s_l-t_r)+t_r-x[i], abs(s_r-t_l)+x[i]-t_l, abs(s_l-t_l)+x[i]-t_l])\n print(long[0])', 'import bisect\nA, B, Q = map(int, input().split())\ns = [int(input()) for i in range(A)]\nt = [int(input()) for i in range(B)]\nx = [int(input()) for i in range(Q)]\ninf = [10**13, -10**13]\ns = sorted(s+inf)\nt = sorted(t+inf)\n\nfor i in range(Q):\n s_r = s[bisect.bisect_right(s, x[i])]\n s_l = s[bisect.bisect_left(s, x[i])-1]\n t_r = t[bisect.bisect_right(t, x[i])]\n t_l = t[bisect.bisect_left(t, x[i])-1]\n long = sorted([abs(t_r-s_r)+s_r-x[i], abs(t_l-s_r)+s_r-x[i], abs(t_l-s_l)+x[i]-s_l, abs(t_r-s_l)+x[i]-s_l,\n abs(s_r-t_r)+t_r-x[i], abs(s_l-t_r)+t_r-x[i], abs(s_r-t_l)+x[i]-t_l, abs(s_l-t_l)+x[i]-t_l])\n print(long[0])']
['Runtime Error', 'Accepted']
['s834844228', 's476288121']
[15044.0, 16772.0]
[484.0, 1150.0]
[689, 638]
p03112
u350836088
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\n\na,b,q = map(int,input().split())\ninf = 10**18\nS = [-inf]+[int(input()) for _ in range(a)]+[inf]\nT = [-inf]+[int(input()) for _ in range(b)]+[inf]\nans = inf\nfor _ in range(q):\n x = int(input())\n b,d = bisect.bisect_right(S,x),bisect.bisect_right(T,x)\n for s in [S[b-1],S[b]]:\n for t in [T[d-1],T[d]]:\n tmp1,tmp2 = abs(s-x)+abs(s-t) ,abs(t-x)+abs(t-s)\n ans = min(ans ,tmp1,tmp2)\n print(ans)\n \n', 'import bisect\n \na,b,q = map(int,input().split())\ninf = 10**18\nS = [-inf]+[int(input()) for _ in range(a)]+[inf]\nT = [-inf]+[int(input()) for _ in range(b)]+[inf]\nans = inf\nfor _ in range(q):\n x = int(input())\n b,d = bisect.bisect_right(S,x),bisect.bisect_right(T,x)\n ans = inf\n for s in [S[b-1],S[b]]:\n for t in [T[d-1],T[d]]:\n tmp1,tmp2 = abs(s-x)+abs(s-t) ,abs(t-x)+abs(t-s)\n ans = min(ans ,tmp1,tmp2)\n print(ans)\n \n\n']
['Wrong Answer', 'Accepted']
['s081486246', 's915915227']
[12800.0, 13840.0]
[1726.0, 1706.0]
[428, 442]
p03112
u353797797
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['with open("td") as inputfile:\n open0=inputfile.read()\n\ndef zengo(l,n):\n if n<l[0]:\n return 0,l[0]-n\n elif n>l[-1]:\n return n-l[-1],0\n else:\n st=0\n ed=len(l)\n while ed-st>1:\n md=(st+ed)//2\n if n<l[md]:\n ed=md\n else:\n st=md\n return n-l[st],l[ed]-n\n\nnear=lambda x,y:min(x,y) if x*y else max(x,y)\n\njn,tn,qn,*tmp=map(int,open0.split())\njz=tmp[:jn]\ntz=tmp[jn:jn+tn]\nq=tmp[jn+tn:]\nfor i in q:\n jb,jf=zengo(jz,i)\n tb,tf=zengo(tz,i)\n ans=[]\n if jb*tb:\n ans.append(max(jb,tb))\n if jf*tf:\n ans.append(max(jf,tf))\n jd=near(jb,jf)\n td=near(tb,tf)\n ans.append(jd+td+min(jd,td))\n print(min(ans))', 'def zengo(l,n):\n if n<l[0]:\n return 0,l[0]-n\n elif n>l[-1]:\n return n-l[-1],0\n else:\n st=0\n ed=len(l)\n while ed-st>1:\n md=(st+ed)//2\n if n<l[md]:\n ed=md\n else:\n st=md\n return n-l[st],l[ed]-n\n\nnear=lambda x,y:min(x,y) if x*y else max(x,y)\n\njn,tn,qn,*tmp=map(int,open(0).read.split())\njz=tmp[:jn]\ntz=tmp[jn:jn+tn]\nq=tmp[jn+tn:]\nfor i in q:\n jb,jf=zengo(jz,i)\n tb,tf=zengo(tz,i)\n ans=[]\n if jb*tb:\n ans.append(max(jb,tb))\n if jf*tf:\n ans.append(max(jf,tf))\n jd=near(jb,jf)\n td=near(tb,tf)\n ans.append(jd+td+min(jd,td))\n print(min(ans))', 'def zengo(l,n):\n if n<l[0]:\n return 0,l[0]-n\n elif n>l[-1]:\n return n-l[-1],0\n else:\n st=0\n ed=len(l)\n while ed-st>1:\n md=(st+ed)//2\n if n<l[md]:\n ed=md\n else:\n st=md\n return n-l[st],l[ed]-n\n\nnear=lambda x,y:min(x,y) if x*y else max(x,y)\n\njn,tn,qn,*tmp=map(int,open(0).split())\njz=tmp[:jn]\ntz=tmp[jn:jn+tn]\nq=tmp[jn+tn:]\nfor i in q:\n jb,jf=zengo(jz,i)\n tb,tf=zengo(tz,i)\n ans=[]\n if jb*tb:\n ans.append(max(jb,tb))\n if jf*tf:\n ans.append(max(jf,tf))\n jd=near(jb,jf)\n td=near(tb,tf)\n ans.append(jd+td+min(jd,td))\n print(min(ans))', 'def zengo(l,n):\n if n<l[0]:\n return 0,l[0]-n\n elif n>l[-1]:\n return n-l[-1],0\n else:\n st=0\n ed=len(l)\n while ed-st>1:\n md=(st+ed)//2\n if n<l[md]:\n ed=md\n else:\n st=md\n return n-l[st],l[ed]-n\n\nnear=lambda x,y:min(x,y) if x*y else max(x,y)\n\njn,tn,qn,*tmp=map(int,open(0).read().split())\njz=tmp[:jn]\ntz=tmp[jn:jn+tn]\nq=tmp[jn+tn:]\nfor i in q:\n jb,jf=zengo(jz,i)\n tb,tf=zengo(tz,i)\n ans=[]\n if jb*tb:\n ans.append(max(jb,tb))\n if jf*tf:\n ans.append(max(jf,tf))\n jd=near(jb,jf)\n td=near(tb,tf)\n ans.append(jd+td+min(jd,td))\n print(min(ans))']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s016411735', 's189229948', 's591908445', 's258766212']
[3064.0, 3064.0, 3064.0, 36612.0]
[18.0, 18.0, 18.0, 1182.0]
[738, 687, 682, 689]
p03112
u360116509
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\n\n\ndef f(a, x):\n i = bisect.bisect_left(a, x)\n if i >= len(a) - 1:\n return a[-1]\n if x - a[i] > a[i + 1] - x:\n return a[i + 1]\n return a[i]\n\n\ndef main():\n A, B, Q = map(int, input().split())\n s = []\n t = []\n ans = []\n for _ in range(A):\n s.append(int(input()))\n for _ in range(B):\n t.append(int(input()))\n for _ in range(Q):\n x = int(input())\n sx = f(s, x)\n tsx = f(t, sx)\n tx = f(t, x)\n stx = f(s, tx)\n ans.append(min(abs(sx - x) + abs(sx - tsx),\n abs(tx - x) + abs(tx - stx)))\n for a in ans:\n print(a)\n\n\nmain()\n', "import bisect\n\ndef main():\n A, B, Q = map(int, input().split())\n s = [-float('inf')]\n t = [-float('inf')]\n ans = []\n for _ in range(A):\n s.append(int(input()))\n for _ in range(B):\n t.append(int(input()))\n s.append(float('inf'))\n t.append(float('inf'))\n for _ in range(Q):\n x = int(input())\n i = bisect.bisect_right(s, x)\n j = bisect.bisect_right(t, x)\n a = float('inf')\n for ss in [s[i - 1], s[i]]:\n for tt in [t[j - 1], t[j]]:\n a = min(a, abs(ss - x) + abs(tt - ss),\n abs(tt - x) + abs(ss - tt))\n ans.append(a)\n for a in ans:\n print(a)\n\n\nmain()\n"]
['Wrong Answer', 'Accepted']
['s567607536', 's588228446']
[16880.0, 16896.0]
[1081.0, 1216.0]
[661, 688]
p03112
u371467115
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['A,B,Q=map(int,input().split())\nINF=10**18\nS=[-INF]+[int(input()) for _ in range(A)]+[INF]\nT=[-INF]+[int(input()) for _ in range(B)]+[INF]\nX=[int(input()) for _ in range(Q)]\n\ndef binary_serch(a,x,st=0,end=len(a)):\n while st<end:\n i=len(a)//2\n if x<a[i]:\n end=i\n elif a[i]<x:\n st=i+1\n return st\n\nfor x in X:\n s,t=binary_serch(S,x),binary_serch(T,x)\n ans=INF\n for j in [S[i],S[i+1]]:\n for k in [T[i],T[i+1]]:\n cnd1,cnd2=abs(j-x)+abs(k-j),abs(k-x),abs(j-k)\n ans(min(ans,cnd1,cnd2))\n print(ans)', 'import bisect\na,b,q=map(int,input().split())\ninf=10**18\ns=[-inf]+[int(input()) for _ in range(a)]+[inf]\nt=[-inf]+[int(input()) for _ in range(b)]+[inf]\nfor _ in range(q):\n x=int(input())\n b,d=bisect.bisect_right(s,x),bisect.bisect_right(t,x)\n res=inf\n for i in [s[b-1],s[b]]:\n for j in [t[d-1],s[d]]:\n d1,d2=abs(i-x)+abs(i-j),abs(j-x)+abs(j-i)\n res=min(res,d1,d2)\n print(res)\n#copy code.\n', 'import bisect\na,b,q=map(int,input())\ninf=10**18\ns=[-inf]+[int(input()) for _ in range(a)]+[inf]\nt=[-inf]+[int(input()) for _ in range(b)]+[inf]\nfor _ in range(q):\n x=int(input())\n b,d=bisect_right(s,x),bisect_right(t,x)\n res=inf\n for i in [s[b-1],s[b]]:\n for j in [t[d-1],s[d]]:\n d1,d2=abs(i-x)+abs(i-j),abs(j-x)+abs(j-i)\n res=min(res,d1,d2)\n print(res)', 'import bisect\na,b,q=map(int,input())\ninf=10**18\ns=[-inf]+[int(input()) for _ in range(a)]+[inf]\nt=[-inf]+[int(input()) for _ in range(b)]+[inf]\nfor _ in range(q):\n x=int(input())\n b,d=bisect.bisect_right(s,x),bisect.bisect_right(t,x)\n res=inf\n for i in [s[b-1],s[b]]:\n for j in [t[d-1],s[d]]:\n d1,d2=abs(i-x)+abs(i-j),abs(j-x)+abs(j-i)\n res=min(res,d1,d2)\n print(res)\n#copy code.', 'import bisect\nA, B, Q = map(int, input().split())\nINF=10**18\ns=[-INF] + [int(input()) for i in range(A)] + [INF]\nt=[-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)\n#copy code.']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s176814885', 's343936974', 's513848190', 's588672798', 's302743630']
[14852.0, 12800.0, 3064.0, 3064.0, 12812.0]
[486.0, 1762.0, 18.0, 18.0, 1668.0]
[527, 406, 371, 397, 454]
p03112
u391875425
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nimport sys\nA, B, Q = map(int, input().split())\nINF = 10 ** 13\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nxs = [int(sys.stdin.readline()) for i in range(Q)]\nfor x in range(xs):\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)', "def solve():\n import bisect\n A, B, Q = map(int, input().split())\n INF = 10 ** 13\n s = [-INF] + [int(input()) for i in range(A)] + [INF]\n t = [-INF] + [int(input()) for i in range(B)] + [INF]\n for q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)\nif __name__ == '__main__':\n \tsolve()"]
['Runtime Error', 'Accepted']
['s712274423', 's326807202']
[14864.0, 14244.0]
[376.0, 1605.0]
[518, 583]
p03112
u392319141
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['from bisect import bisect_right\n\nA , B , Q = map(int,input().split())\nINF = 10**20\n\ns = [0] * A\nt = [0] * B\nx = [0] * Q\n\nfor i in range(A) :\n s[i] = int(input())\nfor i in range(B) :\n t[i] = int(input())\nfor i in range(Q) :\n x[i] = int(input())\n\ns = [INF] + s + [INF]\nt = [INF] + t + [INF]\n\nfor p in x :\n rightS = bisect_right(s,p)\n rightT = bisect_right(t,p)\n\n dist = INF\n\n for i in [s[rightS - 1], s[rightS]] :\n for j in [t[rightT -1], t[rightT]] :\n dist1 = abs(i - p) + abs(i - j)\n dist2 = abs(j - p) + abs(i - j)\n dist = min(dist, dist1, dist2)\n\n print(dist)', 'from bisect import bisect_left\n\nA, B, Q = map(int, input().split())\nINF = 10**18\nS = [int(input()) for _ in range(A)] + [INF, INF, -INF, -INF]\nT = [int(input()) for _ in range(B)] + [INF, INF, -INF, -INF]\n\nS.sort()\nT.sort()\n\nfor _ in range(Q):\n x = int(input())\n\n s = bisect_left(S, x)\n ls = S[s - 1]\n rs = S[s]\n\n t = bisect_left(T, x)\n lt = T[t - 1]\n rt = T[t]\n\n ans = min(\n abs(ls - rt) + min(abs(x - ls), abs(x - rt)),\n abs(lt - rs) + min(abs(x - lt), abs(x - rs)),\n max(abs(x - ls), abs(x - lt)),\n max(abs(x - rs), abs(x - rt))\n )\n\n print(ans)\n']
['Wrong Answer', 'Accepted']
['s091681196', 's405842339']
[17604.0, 12816.0]
[1218.0, 1505.0]
[625, 606]
p03112
u393512980
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect as bs\na, b, q = map(int, input().split())\nINF = 10**18\ns = [-INF] + sorted([int(input()) for _ in range(a)]) + [INF]\nt = [-INF] + sorted([int(input()) for _ in range(b)]) + [INF]\n\nfor _ in range(q):\n z = int(input())\n x, y = bs.bisect_right(s, z), bs.bisect_right(t, z)\n s1, s2, t1, t2 = s[x-1], s[x], t[y-1], t[y]\n print(min(max(z - s1, z - t1), max(s2 - z, t2 - z), min(2 * t2 - z - s1, 2 * s2 - z - t1)))', 'import bisect as bs\na, b, q = map(int, input().split())\nINF = 10**18\ns = [-INF] + sorted([int(input()) for _ in range(a)]) + [INF]\nt = [-INF] + sorted([int(input()) for _ in range(b)]) + [INF]\n\nfor _ in range(q):\n z = int(input())\n x, y = bs.bisect_right(s, z), bs.bisect_right(t, z)\n s1, s2, t1, t2 = s[x-1], s[x], t[y-1], t[y]\n print(min(max(z - s1, z - t1), max(s2 - z, t2 - z),\n min(2 * t2 - z - s1, 2 * s2 - z - t1), min(z + t2 - 2 * s1, z + s2 - 2 * t1)))']
['Wrong Answer', 'Accepted']
['s567641588', 's111240349']
[12784.0, 12784.0]
[1414.0, 1480.0]
[433, 476]
p03112
u411858517
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\n\nA, B, Q = map(int, input().split())\ns = [int(input()) for _ in range(A)]\nt = [int(input()) for _ in range(B)]\nx = [int(input()) for _ in range(Q)]\n\n\nfor i in range(Q):\n\n insert_index = bisect.bisect_left(s,x[i])\n if insert_index >= A:\n insert_index = insert_index -1\n tmp1 = s[insert_index]\n tmp2 = s[insert_index]\n \n elif insert_index == 0:\n tmp1 = s[insert_index]\n tmp2 = s[insert_index]\n else: \n tmp1 = s[insert_index]\n tmp2 = s[insert_index-1]\n \n insert_index = bisect.bisect_left(t,x[i])\n if insert_index >= B or insert_index == 0:\n insert_index = insert_index -1\n tmp3 = t[insert_index]\n tmp4 = t[insert_index]\n \n elif:\n tmp3 = t[insert_index]\n tmp4 = t[insert_index]\n \n else:\n tmp3 = t[insert_index]\n tmp4 = t[insert_index-1]\n \n result = 10 ** 11\n for j, k in ([0,1], [0,0], [1,0], [1,1]):\n tmp = 0\n if j == 0:\n tmp += abs(tmp1 - x[i])\n now = tmp1\n else:\n tmp += abs(tmp2 - x[i])\n now = tmp2\n \n if k == 0:\n tmp += abs(now - tmp3)\n else:\n tmp += abs(now - tmp4)\n \n result = min(tmp, result)\n \n print(result)\n\n', 'import bisect\n\nA, B, Q = map(int, input().split())\ns = [int(input()) for _ in range(A)]\nt = [int(input()) for _ in range(B)]\nx = [int(input()) for _ in range(Q)]\n\n\nfor i in range(Q):\n\n insert_index = bisect.bisect_left(s,x[i])\n if insert_index >= A:\n insert_index = insert_index -1\n tmp1 = s[insert_index]\n tmp2 = s[insert_index]\n \n elif insert_index == 0:\n tmp1 = s[insert_index]\n tmp2 = s[insert_index]\n else: \n tmp1 = s[insert_index]\n tmp2 = s[insert_index-1]\n \n insert_index = bisect.bisect_left(t,x[i])\n if insert_index >= B or insert_index == 0:\n insert_index = insert_index -1\n tmp3 = t[insert_index]\n tmp4 = t[insert_index]\n \n elif:\n tmp1 = t[insert_index]\n tmp2 = t[insert_index]\n \n else:\n tmp3 = t[insert_index]\n tmp4 = t[insert_index-1]\n \n result = 10 ** 11\n for j, k in ([0,1], [0,0], [1,0], [1,1]):\n tmp = 0\n if j == 0:\n tmp += abs(tmp1 - x[i])\n now = tmp1\n else:\n tmp += abs(tmp2 - x[i])\n now = tmp2\n \n if k == 0:\n tmp += abs(now - tmp3)\n else:\n tmp += abs(now - tmp4)\n \n result = min(tmp, result)\n \n print(result)\n\n', 'import bisect\nimport itertools\n\n\ndef bit(n, m):\n bit_list = list(itertools.product([i for i in range(m)], repeat=n))\n return bit_list\n\nA, B, Q = map(int, input().split())\ns = [int(input()) for _ in range(A)]\nt = [int(input()) for _ in range(B)]\nx = [int(input()) for _ in range(Q)]\n\n\nfor i in range(Q):\n\n insert_index = bisect.bisect_left(s,x[i])\n if insert_index >= A:\n insert_index = insert_index -1\n tmp1 = s[insert_index]\n tmp2 = s[insert_index]\n \n else: \n tmp1 = s[insert_index]\n tmp2 = s[insert_index-1]\n \n insert_index = bisect.bisect_left(t,x[i])\n if insert_index >= B:\n insert_index = insert_index -1\n tmp3 = t[insert_index]\n tmp4 = t[insert_index]\n \n else:\n tmp3 = t[insert_index]\n tmp4 = t[insert_index-1]\n \n result = 10 ** 11\n for j, k in ([0,1], [0,0], [1,0], [1,1]):\n tmp = 0\n if j == 0:\n tmp += abs(tmp1 - x[i])\n now = tmp1\n else:\n tmp += abs(tmp2 - x[i])\n now = tmp2\n \n if k == 0:\n tmp += abs(now - tmp3)\n else:\n tmp += abs(now - tmp4)\n \n result = min(tmp, result)\n \n for j, k in ([0,1], [0,0], [1,0], [1,1]):\n tmp = 0\n \n if k == 0:\n tmp += abs(x[i] - tmp3)\n now = tmp3\n else:\n tmp += abs(x[i]- tmp4)\n now = tmp4\n \n if j == 0:\n tmp += abs(now - tmp1)\n else:\n tmp += abs(now - tmp2)\n \n result = min(tmp, result)\n \n print(result)\n\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s123371069', 's704632382', 's431885813']
[3064.0, 3064.0, 16188.0]
[17.0, 17.0, 1542.0]
[1343, 1343, 1701]
p03112
u427344224
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['A, B, Q = map(int, input().split())\ns_list = [int(input()) for i in range(A)]\nt_list = [int(input()) for i in range(B)]\nx_list = [int(input()) for _ in range(Q)]\n\ns_list.sort()\nt_list.sort()\nimport bisect\n\nans = []\nfor x in x_list:\n tmp = float("inf")\n s_i = bisect.bisect_left(s_list, x)\n t_i = bisect.bisect_left(t_list, x)\n\n if s_i == A and t_i == B:\n tmp = abs(x - min(s_list[-1], t_list[-1]))\n ans.append(tmp)\n continue\n if s_i == A:\n if t_i != 0:\n tmp = abs(s_list[-1] - x)\n if s_list[-1] <= t_list[t_i] <= x:\n ans.append(tmp)\n continue\n else:\n tmp += min(abs(t_list[t_i] - x) * 2, abs(t_list[t_i - 1] - s_list[-1]))\n else:\n tmp = abs(min(abs(s_list[s_i - 1] - x), abs(t_list[0] - x)) * 2 + max(abs(s_list[s_i - 1] - x),\n abs(t_list[0] - x)))\n ans.append(tmp)\n continue\n if t_i == B:\n if s_i != 0:\n tmp = abs(t_list[-1] - x)\n if t_list[-1] <= s_list[s_i] <= x:\n ans.append(tmp)\n continue\n else:\n tmp += min(abs(s_list[s_i] - x) * 2, abs(s_list[s_i - 1] - t_list[-1]))\n else:\n tmp = abs(min(abs(t_list[t_i - 1] - x), abs(s_list[0] - x)) * 2 + max(abs(t_list[t_i - 1] - x),\n abs(s_list[0] - x)))\n ans.append(tmp)\n continue\n\n # S1, T1\n if s_i != 0 and t_i != 0:\n tmp = min(tmp, abs(min(s_list[s_i - 1], t_list[t_i - 1]) - x))\n elif s_i == 0 and t_i == 0:\n tmp = min(tmp, abs(x - max(s_list[0], t_list[0])))\n elif s_i == 0 and t_i != 0:\n tmp = min(tmp, abs(s_list[0] - t_list[t_i]))\n else:\n tmp = min(tmp, abs(t_list[0] - s_list[s_i]))\n\n # S2, T2\n tmp = min(tmp, abs(max(s_list[s_i], t_list[t_i]) - x))\n\n # S1, T2\n if s_i != 0:\n tmp = min(tmp, abs(min(abs(t_list[t_i] - x), abs(s_list[s_i - 1] - x)) * 2 + max(abs(t_list[t_i] - x),\n abs(s_list[s_i - 1] - x))))\n else:\n tmp = min(tmp, abs(max(t_list[t_i], s_list[0]) - x))\n # S2, T1\n if t_i != 0:\n tmp = min(tmp, abs(min(abs(s_list[s_i] - x), abs(t_list[t_i - 1] - x)) * 2 + max(abs(s_list[s_i] - x),\n abs(t_list[t_i - 1] - x))))\n else:\n tmp = min(tmp, abs(max(s_list[s_i], t_list[0]) - x))\n ans.append(tmp)\nfor a in ans:\n print(a)\n', 'A, B, Q = map(int, input().split())\ns_list = [int(input()) for i in range(A)]\nt_list = [int(input()) for i in range(B)]\nx_list = [int(input()) for _ in range(Q)]\n\ns_list.sort()\nt_list.sort()\nimport bisect\n\nans = []\nfor x in x_list:\n tmp = float("inf")\n s_i = bisect.bisect_left(s_list, x)\n t_i = bisect.bisect_left(t_list, x)\n\n if s_i == A and t_i == B:\n tmp = abs(x - min(s_list[-1], t_list[-1]))\n ans.append(tmp)\n continue\n if s_i == A:\n if t_i != 0:\n tmp = abs(s_list[-1] - x)\n if s_list[-1] <= t_list[t_i] <= x:\n ans.append(tmp)\n continue\n else:\n tmp += min(abs(t_list[t_i] - x) * 2, abs(t_list[t_i - 1] - s_list[-1]))\n else:\n tmp = abs(min(abs(s_list[s_i - 1] - x), abs(t_list[0] - x)) * 2 + max(abs(s_list[s_i - 1] - x),\n abs(t_list[0] - x)))\n ans.append(tmp)\n continue\n if t_i == B:\n if s_i != 0:\n tmp = abs(t_list[-1] - x)\n if t_list[-1] <= s_list[s_i] <= x:\n ans.append(tmp)\n continue\n else:\n tmp += min(abs(s_list[s_i] - x) * 2, abs(s_list[s_i - 1] - t_list[-1]))\n else:\n tmp = abs(min(abs(t_list[t_i - 1] - x), abs(s_list[0] - x)) * 2 + max(abs(t_list[t_i - 1] - x),\n abs(s_list[0] - x)))\n ans.append(tmp)\n continue\n\n # S1, T1\n if s_i != 0 and t_i != 0:\n tmp = min(tmp, abs(min(s_list[s_i - 1], t_list[t_i - 1]) - x))\n elif s_i == 0 and t_i == 0:\n tmp = min(tmp, abs(x - max(s_list[0], t_list[0])))\n elif s_i == 0 and t_i != 0:\n tmp = min(tmp, abs(s_list[0] - t_list[t_i]))\n else:\n tmp = min(tmp, abs(t_list[0] - s_list[s_i]))\n\n # S2, T2\n tmp = min(tmp, abs(max(s_list[s_i], t_list[t_i]) - x))\n\n # S1, T2\n if s_i != 0:\n tmp = min(tmp, abs(min(abs(t_list[t_i] - x), abs(s_list[s_i - 1] - x)) * 2 + max(abs(t_list[t_i] - x),\n abs(s_list[s_i - 1] - x))))\n else:\n tmp = min(tmp, abs(max(t_list[t_i], s_list[0]) - x))\n # S2, T1\n if t_i != 0:\n tmp = min(tmp, abs(min(abs(s_list[s_i] - x), abs(t_list[t_i - 1] - x)) * 2 + max(abs(s_list[s_i] - x),\n abs(t_list[t_i - 1] - x))))\n else:\n tmp = min(tmp, abs(max(s_list[s_i], t_list[0]) - x))\n ans.append(tmp)\nfor a in ans:\n print(a)\n', 'from bisect import bisect_left\n\nA, B, Q = map(int, input().split())\ns_list = [int(input()) for _ in range(A)]\nt_list = [int(input()) for _ in range(B)]\nx_list = [int(input()) for _ in range(Q)]\n\ninf = float("inf")\n\ns_list = [-inf] + s_list + [inf]\nt_list = [-inf] + t_list + [inf]\n\nfor x in x_list:\n\n s_i = bisect_left(s_list, x)\n t_i = bisect_left(t_list, x)\n\n ans = inf\n for s in (s_list[s_i - 1], s_list[s_i]):\n for t in (t_list[t_i - 1], t_list[t_i]):\n d1 = abs(s - x) + abs(t - s)\n d2 = abs(t - x) + abs(s - t)\n ans = min(ans, d1, d2)\n print(ans)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s269078861', 's636740526', 's338431606']
[20376.0, 20372.0, 16772.0]
[1202.0, 1193.0, 1174.0]
[2695, 2695, 607]
p03112
u465699806
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['a,b,q=[int(it) for it in input().split()]\ndummy=10**20\ns=[-dummy] + [int(input()) for it in range(a)] + [dummy]\nt=[-dummy] + [int(input()) for it in range(b)] + [dummy]\nx=[int(input()) for it in range(q)]\n\ndef find_left(l, p):\n a,b=0,len(l)-1\n while True:\n c=(a+b)//2\n if p <= l[c]:\n b = c-1\n elif l[c+1] <= p:\n a = c+1\n else:\n return c\ndef find_right(l, p):\n a,b=0,len(l)-1\n while True:\n c=(a+b)//2\n if p <= l[c-1]:\n b = c-1\n elif l[c] <= p:\n a = c+1\n else:\n return c\nfor xi in x:\n s_w = s[find_left(s, xi)]\n s_e = s[find_right(s, xi)]\n t_w = t[find_left(t, xi)]\n t_e = t[find_right(t, xi)]\n\n d = min(\n abs(xi - s_w) + abs(s_w - t_w),\n abs(xi - s_e) + abs(s_e - t_w),\n abs(xi - s_w) + abs(s_w - t_e),\n abs(xi - s_e) + abs(s_e - t_e),\n abs(xi - t_w) + abs(t_w - s_w),\n abs(xi - t_e) + abs(t_e - s_w),\n abs(xi - t_w) + abs(t_w - s_e),\n abs(xi - t_e) + abs(t_e - s_e)\n )\n print(d)\n', 'import bisect\n\na,b,q=[int(it) for it in input().split()]\ndummy=10**20\ns=[-dummy] + [int(input()) for it in range(a)] + [dummy]\nt=[-dummy] + [int(input()) for it in range(b)] + [dummy]\nx=[int(input()) for it in range(q)]\n\nfor xi in x:\n s_w = s[bisect.bisect_left(s, xi)-1]\n s_e = s[bisect.bisect_left(s, xi)]\n t_w = t[bisect.bisect_left(t, xi)-1]\n t_e = t[bisect.bisect_left(t, xi)]\n\n d = min(\n abs(xi - s_w) + abs(s_w - t_w),\n abs(xi - s_e) + abs(s_e - t_w),\n abs(xi - s_w) + abs(s_w - t_e),\n abs(xi - s_e) + abs(s_e - t_e),\n abs(xi - t_w) + abs(t_w - s_w),\n abs(xi - t_e) + abs(t_e - s_w),\n abs(xi - t_w) + abs(t_w - s_e),\n abs(xi - t_e) + abs(t_e - s_e)\n )\n print(d)\n']
['Time Limit Exceeded', 'Accepted']
['s135433516', 's534245060']
[15504.0, 16144.0]
[2105.0, 1072.0]
[1090, 746]
p03112
u467736898
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['# %2\nclass AvlTree: # std::set\n def __init__(self, values=None, sorted_=False):\n if values is None:\n self.left = [-1]\n self.right = [-1]\n self.values = [-float("inf")]\n self.diff = [0] # left - right\n self.size_l = [0]\n else:\n n = len(values)\n self.left = [-1] * (n+1)\n self.right = [-1] * (n+1)\n self.values = [-float("inf")] + values\n self.diff = [0] * (n+1) # left - right\n self.size_l = [0] * (n+1)\n if not sorted_:\n values.sort()\n\n st = [[1, n+1, 0]]\n while len(st) > 0:\n l, r, idx_par = st.pop() \n c = (l+r) % 2\n if self.values[c] < self.values[idx_par]:\n self.left[idx_par] = c\n else:\n self.right[idx_par] = c\n siz = r - l\n if siz & -siz == siz and siz != 1: \n self.diff[c] = 1\n siz_l = c - l\n self.size_l[c] = siz_l\n if siz_l > 0:\n st.append([l, c, c])\n c1 = c + 1\n if c1 < r: \n st.append([c1, r, c])\n\n \n # print(f"left ={self.left}")\n # print(f"right ={self.right}")\n # print(f"values={self.values}")\n # print(f"diff ={self.diff}")\n # print(f"dixr_l={self.size_l}")\n\n def rotate_right(self, idx_par, lr): \n idx = self.left[idx_par] if lr==0 else self.right[idx_par]\n idx_l = self.left[idx]\n assert idx_l != -1 \n\n \n self.size_l[idx] -= self.size_l[idx_l] + 1\n\n \n a = self.diff[idx]\n b = self.diff[idx_l] \n if b >= 0:\n na = a - 1 - b\n if na >= 0:\n nb = b - 1\n else:\n nb = a - 2\n else:\n na = a - 1\n if na >= 0:\n nb = b - 1\n else:\n nb = a + b - 2\n self.diff[idx] = na\n self.diff[idx_l] = nb\n\n \n self.left[idx] = self.right[idx_l]\n self.right[idx_l] = idx\n if lr==0:\n self.left[idx_par] = idx_l\n else:\n self.right[idx_par] = idx_l\n\n def rotate_left(self, idx_par, lr): \n idx = self.left[idx_par] if lr==0 else self.right[idx_par]\n idx_r = self.right[idx]\n assert idx_r != -1 \n\n \n self.size_l[idx_r] += self.size_l[idx] + 1\n\n \n a = self.diff[idx]\n b = self.diff[idx_r] \n if b <= 0:\n na = a + 1 - b\n if na <= 0:\n nb = b + 1\n else:\n nb = a + 2\n else:\n na = a + 1\n if na <= 0:\n nb = b + 1\n else:\n nb = a + b + 2\n self.diff[idx] = na\n self.diff[idx_r] = nb\n\n \n self.right[idx] = self.left[idx_r]\n self.left[idx_r] = idx\n if lr == 0:\n self.left[idx_par] = idx_r\n else:\n self.right[idx_par] = idx_r\n\n def add(self, x): # insert\n idx = 0\n path = []\n path_left = []\n while idx != -1:\n path.append(idx)\n value = self.values[idx]\n if x == value:\n return \n elif x < value:\n path_left.append(idx)\n idx = self.left[idx]\n else:\n idx = self.right[idx]\n\n if x < value:\n self.left[path[-1]] = len(self.values)\n else:\n self.right[path[-1]] = len(self.values)\n self.left.append(-1)\n self.right.append(-1)\n self.values.append(x)\n self.diff.append(0)\n self.size_l.append(0)\n\n for idx_ in path_left:\n self.size_l[idx_] += 1\n\n self.diff[path[-1]] += 1 if x < value else -1\n for idx, idx_par in zip(path[:0:-1], path[-2::-1]):\n diff = self.diff[idx]\n if diff == 0:\n return\n elif diff == 2: \n idx_l = self.left[idx] \n if self.diff[idx_l] == -1: \n self.rotate_left(idx, 0)\n self.rotate_right(idx_par, self.right[idx_par]==idx)\n return\n elif diff == -2: \n idx_r = self.right[idx] \n if self.diff[idx_r] == 1: \n self.rotate_right(idx, 1)\n self.rotate_left(idx_par, self.right[idx_par]==idx)\n return\n else:\n self.diff[idx_par] += 1 if self.left[idx_par]==idx else -1\n\n def remove(self): \n raise NotImplementedError\n\n def __contains__(self, x): # count\n raise NotImplementedError\n\n def bisect_left(self, x): # lower_bound\n idx = self.right[0]\n res = 0\n while idx != -1:\n value = self.values[idx]\n if value == x:\n return res + self.size_l[idx]\n elif value < x:\n res += self.size_l[idx] + 1\n idx = self.right[idx]\n else:\n idx = self.left[idx]\n return res\n\n def bisect_right(self): # upper_bound\n raise NotImplementedError\n\n\nfrom bisect import bisect_left\nimport sys\ninput = sys.stdin.readline\nA, B, Q = map(int, input().split())\n\nS = [int(input()) for _ in range(A)]\nT = [int(input()) for _ in range(B)]\navl_S = AvlTree(S, True)\navl_T = AvlTree(T, True)\n\ndef f(x):\n if 0 <= x and A - 1 >= x:\n return True\n return False\ndef g(x):\n if 0 <= x and B - 1 >= x:\n return True\n return False\n\nfor i in range(Q):\n x = int(input())\n p = avl_S.bisect_left(x)\n m = avl_T.bisect_left(x)\n\n res = []\n if f(p) and g(m):\n res.append(max(T[m], S[p]) - x)\n if f(p) and g(m - 1):\n res.append(min(S[p] - x, x - T[m - 1]) + S[p] - T[m - 1])\n if f(p - 1) and g(m):\n res.append(T[m] - S[p - 1] + min(T[m] - x, x - S[p - 1]))\n if f(p - 1) and g(m - 1):\n res.append(x - min(T[m - 1], S[p - 1]))\n print(min(res))\n', '\nclass AvlTree: # std::set\n def __init__(self, values=None, sorted_=False):\n if values is None:\n self.left = [-1]\n self.right = [-1]\n self.values = [-float("inf")]\n self.diff = [0] # left - right\n self.size_l = [0]\n else:\n if not sorted_:\n values.sort()\n n = len(values)\n self_left = self.left = [-1] * (n+1)\n self_right = self.right = [-1] * (n+1)\n self_values = self.values = [-float("inf")] + values\n self_diff = self.diff = [0] * (n+1) # left - right\n self_size_l = self.size_l = [0] * (n+1)\n\n st = [[1, n+1, 0]]\n while len(st) > 0:\n l, r, idx_par = st.pop() \n c = (l+r) // 2 # pypy -> >>1\n if self_values[c] < self_values[idx_par]:\n self_left[idx_par] = c\n else:\n self_right[idx_par] = c\n siz = r - l\n if siz & -siz == siz != 1: \n self_diff[c] = 1\n siz_l = c - l\n self_size_l[c] = siz_l\n if siz_l > 0:\n st.append([l, c, c])\n c1 = c + 1\n if c1 < r: \n st.append([c1, r, c])\n\n \n # print(f"left ={self.left}")\n # print(f"right ={self.right}")\n # print(f"values={self.values}")\n # print(f"diff ={self.diff}")\n # print(f"dixr_l={self.size_l}")\n\n def rotate_right(self, idx_par, lr): \n idx = self.left[idx_par] if lr==0 else self.right[idx_par]\n idx_l = self.left[idx]\n assert idx_l != -1 \n\n \n self.size_l[idx] -= self.size_l[idx_l] + 1\n\n \n a = self.diff[idx]\n b = self.diff[idx_l] \n if b >= 0:\n na = a - 1 - b\n if na >= 0:\n nb = b - 1\n else:\n nb = a - 2\n else:\n na = a - 1\n if na >= 0:\n nb = b - 1\n else:\n nb = a + b - 2\n self.diff[idx] = na\n self.diff[idx_l] = nb\n\n \n self.left[idx] = self.right[idx_l]\n self.right[idx_l] = idx\n if lr==0:\n self.left[idx_par] = idx_l\n else:\n self.right[idx_par] = idx_l\n\n def rotate_left(self, idx_par, lr): \n idx = self.left[idx_par] if lr==0 else self.right[idx_par]\n idx_r = self.right[idx]\n assert idx_r != -1 \n\n \n self.size_l[idx_r] += self.size_l[idx] + 1\n\n \n a = self.diff[idx]\n b = self.diff[idx_r] \n if b <= 0:\n na = a + 1 - b\n if na <= 0:\n nb = b + 1\n else:\n nb = a + 2\n else:\n na = a + 1\n if na <= 0:\n nb = b + 1\n else:\n nb = a + b + 2\n self.diff[idx] = na\n self.diff[idx_r] = nb\n\n \n self.right[idx] = self.left[idx_r]\n self.left[idx_r] = idx\n if lr == 0:\n self.left[idx_par] = idx_r\n else:\n self.right[idx_par] = idx_r\n\n def add(self, x): # insert\n idx = 0\n path = []\n path_left = []\n while idx != -1:\n path.append(idx)\n value = self.values[idx]\n if x == value:\n return \n elif x < value:\n path_left.append(idx)\n idx = self.left[idx]\n else:\n idx = self.right[idx]\n\n if x < value:\n self.left[path[-1]] = len(self.values)\n else:\n self.right[path[-1]] = len(self.values)\n self.left.append(-1)\n self.right.append(-1)\n self.values.append(x)\n self.diff.append(0)\n self.size_l.append(0)\n\n for idx_ in path_left:\n self.size_l[idx_] += 1\n\n self.diff[path[-1]] += 1 if x < value else -1\n for idx, idx_par in zip(path[:0:-1], path[-2::-1]):\n diff = self.diff[idx]\n if diff == 0:\n return\n elif diff == 2: \n idx_l = self.left[idx] \n if self.diff[idx_l] == -1: \n self.rotate_left(idx, 0)\n self.rotate_right(idx_par, self.right[idx_par]==idx)\n return\n elif diff == -2: \n idx_r = self.right[idx] \n if self.diff[idx_r] == 1: \n self.rotate_right(idx, 1)\n self.rotate_left(idx_par, self.right[idx_par]==idx)\n return\n else:\n self.diff[idx_par] += 1 if self.left[idx_par]==idx else -1\n\n def remove(self): \n raise NotImplementedError\n\n def __contains__(self, x): # count\n raise NotImplementedError\n\n def bisect_left(self, x): # lower_bound\n self_left = self.left\n self_right = self.right\n self_values = self.values\n self_size_l = self.size_l\n\n idx = self_right[0]\n res = 0\n while idx != -1:\n value = self_values[idx]\n if value == x:\n return res + self_size_l[idx]\n elif value < x:\n res += self_size_l[idx] + 1\n idx = self_right[idx]\n else:\n idx = self_left[idx]\n return res\n\n def bisect_right(self): # upper_bound\n raise NotImplementedError\n\n\nfrom bisect import bisect_left\nimport sys\ninput = sys.stdin.readline\nA, B, Q = map(int, input().split())\n\nS = [int(input()) for _ in range(A)]\nT = [int(input()) for _ in range(B)]\navl_S = AvlTree(S, True)\navl_T = AvlTree(T, True)\n\nfor _ in range(Q):\n x = int(input())\n p = avl_S.bisect_left(x)\n m = avl_T.bisect_left(x)\n\n mi = 1<<60\n if p < A:\n if m < B:\n mi = min(mi, max(T[m], S[p]) - x)\n if 0 < m:\n mi = min(mi, min(S[p] - x, x - T[m - 1]) + S[p] - T[m - 1])\n if 0 < p:\n if m < B:\n mi = min(mi, T[m] - S[p - 1] + min(T[m] - x, x - S[p - 1]))\n if 0 < m:\n mi = min(mi, x - min(T[m - 1], S[p - 1]))\n print(mi)\n']
['Time Limit Exceeded', 'Accepted']
['s744784315', 's413129483']
[21004.0, 26468.0]
[2105.0, 1655.0]
[6648, 6727]
p03112
u476604182
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
["from bisect import bisect_left\nA, B, Q, *L = map(int, open(0).read().split())\ns = L[:A]\nt = L[A:A+B]\nx = L[A+B:]\n\ns = [-float('inf')]+s+[float('inf')]\nt = [-float('inf')]+t+[float('inf')]\nfor c in x:\n br = bisect_left(t,c)\n ar = bisect_left(s,c)\n bl = br-1\n al = ar-1\n print(min(s[ar]-t[bl]+min(s[ar]-c,c-t[bl]),t[br]-s[al]+min(t[br]-c,c-s[al]),\n -min(t[bl],s[al]),max(s[ar],t[br])-c))", 'from bisect import bisect_left\nINF = 10**18\nA, B, Q = map(int, input().split())\nals = [int(input()) for i in range(A)]\nbls = [int(input()) for i in range(B)]\nals = [-INF]+als+[INF]\nbls = [-INF]+bls+[INF]\n\nfor i in range(Q):\n x = int(input())\n ai = bisect_left(x,als)\n bi = bisect_left(x,bls)\n res = INF\n for S in [als[ai], als[ai-1]]:\n for T in [bls[bi], bls[bi-1]]:\n d1, d2 = abs(S-x)+abs(T-S), abs(T-x)+abs(S-T)\n res = min(res,d1,d2)\n print(res)', "import numpy as np\nA, B, Q, *L = map(int, open('0').read().split())\ns = L[:A]\nt = L[A:A+B]\nx = L[A+B:]\n\ns = [-float('inf')]+s+[float('inf')]\nt = [-float('inf')]+t+[float('inf')]\nsls = np.searchsorted(s,x)\ntls = np.searchsorted(t,x)\nfor ar, br, c in zip(sls,tls,x):\n bl = br-1\n al = ar-1\n n = s[ar]-t[bl]+min(s[ar]-c,c-t[bl])\n m = t[br]-s[al]+min(t[br]-c,c-s[al])\n p = c-min(t[bl],s[al])\n q = max(s[ar],t[br])-c\n print(min(n,m,p,q))", 'from bisect import bisect_right\nINF = 10**18\nA, B, Q = map(int, input().split())\nals = [int(input()) for i in range(A)]\nbls = [int(input()) for i in range(B)]\nals = [-INF]+als+[INF]\nbls = [-INF]+bls+[INF]\n\nfor i in range(Q):\n x = int(input())\n ai = bisect_right(x,als)\n bi = bisect_right(x,bls)\n res = INF\n for S in [als[ai], als[ai-1]]:\n for T in [bls[bi], bls[bi-1]]:\n d1, d2 = abs(S-x)+abs(T-S), abs(T-x)+abs(S-T)\n res = min(res,d1,d2)\n print(res)', "from bisect import bisect_left\nA, B, Q, *L = map(int, open(0).read().split())\ns = L[:A]\nt = L[A:A+B]\nx = L[A+B:]\n\ns = [-float('inf')]+s+[float('inf')]\nt = [-float('inf')]+t+[float('inf')]\nfor c in x:\n br = bisect_left(t,c)\n ar = bisect_left(s,c)\n bl = br-1\n al = ar-1\n print(min(s[ar]-t[bl]+min(s[ar]-c,c-t[bl]),t[br]-s[al]+min(t[br]-c,c-s[al]),\n c-min(t[bl],s[al]),max(s[ar],t[br])-c))"]
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s241861163', 's291308244', 's304070158', 's720387444', 's395835659']
[36604.0, 12604.0, 12500.0, 12604.0, 36612.0]
[579.0, 329.0, 150.0, 324.0, 571.0]
[401, 466, 438, 469, 402]
p03112
u489959379
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
["import sys\nfrom bisect import bisect_left\n\nsys.setrecursionlimit(10 ** 7)\ninput = sys.stdin.readline\nf_inf = float('inf')\nmod = 10 ** 9 + 7\n\n\ndef resolve():\n a, b, q = map(int, input().split())\n S = [-f_inf] + list(int(input()) for _ in range(a)) + [f_inf]\n T = [-f_inf] + list(int(input()) for _ in range(b)) + [f_inf]\n\n for _ in range(q):\n res = f_inf\n x = int(input())\n\n idx_s = bisect_left(S, x)\n kouho_s = [idx_s - 1, idx_s]\n for idx_s in kouho_s:\n now = S[idx_s]\n dist = abs(x - now)\n idx_t = bisect_left(T, now)\n kouho_t = [idx_t - 1, idx_t]\n for idx_t in kouho_t:\n dist += abs(now - T[idx_t])\n res = min(res, dist)\n\n idx_t = bisect_left(T, x)\n kouho_t = [idx_t - 1, idx_t]\n for idx_t in kouho_t:\n now = T[idx_t]\n dist = abs(x - now)\n idx_s = bisect_left(S, now)\n kouho_s = [idx_s - 1, idx_s]\n for idx_s in kouho_s:\n dist += abs(now - S[idx_s])\n res = min(res, dist)\n print(res)\n\n\nif __name__ == '__main__':\n resolve()\n", "import sys\nfrom bisect import bisect_left\n\nsys.setrecursionlimit(10 ** 7)\nf_inf = float('inf')\nmod = 10 ** 9 + 7\n\n\ndef neighborhood(L, now):\n tmp = bisect_left(L, now)\n if tmp == 0:\n return [tmp, None]\n elif tmp == len(L):\n return [tmp - 1, None]\n else:\n return [tmp - 1, tmp]\n\n\ndef dist_calc(now, p1, p2):\n if p1 is None or p2 is None:\n return f_inf\n res1 = abs(now - p1) + abs(p1 - p2)\n res2 = abs(now - p2) + abs(p1 - p2)\n return min(res1, res2)\n\n\ndef resolve():\n a, b, q = map(int, input().split())\n S = list(int(input()) for _ in range(a))\n T = list(int(input()) for _ in range(b))\n query = list(int(input()) for _ in range(q))\n\n for x in query:\n dist1 = f_inf\n s1, s2 = neighborhood(S, x)\n for s in [s1, s2]:\n if s is not None:\n t1, t2 = neighborhood(T, S[s])\n for t in [t1, t2]:\n if t is not None:\n dist1 = min(dist1, dist_calc(x, S[s], T[t]))\n\n dist2 = f_inf\n t1, t2 = neighborhood(T, x)\n for t in [t1, t2]:\n if t is not None:\n s1, s2 = neighborhood(S, T[t])\n for s in [s1, s2]:\n if s is not None:\n dist2 = min(dist2, dist_calc(x, S[s], T[t]))\n\n res = min(dist1, dist2)\n print(res)\n\n\nif __name__ == '__main__':\n resolve()\n"]
['Wrong Answer', 'Accepted']
['s909513250', 's212721576']
[17792.0, 20848.0]
[687.0, 1367.0]
[1174, 1422]
p03112
u517447467
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import numpy as np\n\nhint = list(map(int, input().split()))\ns = [int(input()) for i in range(sum(hint))]\n#print(s)\n\na = np.asarray(s[:hint[0]])\nb = np.asarray(s[hint[0]:-hint[2]])\nsum = 0\nfor t in s[-hint[2]:]:\n a_dis = np.abs(a-t).min()\n b_dis = np.abs(b-t).min()\n print(np.min([np.abs(b_dis-t) + np.min(np.abs(a-b_dis)), np.abs(b_dis-t) + np.min(np.abs(b-a_dis))]))', 'import numpy as np\n\nhint = list(map(int, input().split()))\ns = [int(input()) for i in range(sum(hint))]\n# print(s)\n\na = np.asarray(s[:hint[0]])\nb = np.asarray(s[hint[0]:-hint[2]])\nsum = 0\nfor t in s[-hint[2]:]:\n a_dis = np.argmin(np.abs(a - t)[a > t-1000 and a < t+1000])\n b_dis = np.argmin(np.abs(b - t))\n print(np.min([np.abs(b[b_dis] - t) + np.min(np.abs(a[np.max([a_dis-1,0]):a_dis+1] - b[b_dis])), np.abs(a[a_dis] - t) + np.min(np.abs(b[np.max([b_dis-1,0]):b_dis+1] - a[a_dis]))]))', 'import bisect\nimport numpy as np\n \nhint = list(map(int, input().split()))\ns = [int(input()) for i in range(sum(hint))]\n# print(s)\n\ndef search_min_pos(arr, target):\n index = bisect.bisect_left(arr, target)\n if 0 == index:\n dist = arr[index]\n else:\n dist = arr[index-1:index+1]\n if not isinstance(dist, list):\n dist = [dist]\n return dist\n\na_arr = s[:hint[0]]\nb_arr = s[hint[0]:-hint[2]]\nsum = 0\nfor t in s[-hint[2]:]:\n a_pos = search_min_pos(a_arr, t)\n b_pos = search_min_pos(b_arr, t)\n \n min_dist = 10 ** 11\n for a in a_pos:\n b_against_a = search_min_pos(b_arr, a)\n for ba in b_against_a:\n min_dist = min([min_dist, abs(t-a)+abs(ba-a)])\n for b in b_pos:\n a_against_b = search_min_pos(a_arr, b)\n for ab in a_against_b:\n min_dist = min([min_dist, abs(t-b)+abs(ab-b)])\n print(min_dist)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s348651532', 's417855657', 's435752338']
[27852.0, 27776.0, 27692.0]
[2109.0, 644.0, 1832.0]
[375, 495, 847]
p03112
u518042385
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\na,b,q=map(int,input().split())\nls=[-10**11]\nlg=[-10**11]\nfor i in range(a):\n ls.append(int(input()))\nfor i in range(b):\n lg.append(int(input()))\nls.append(10**11)\nlg.append(10**11)\nls=sorted(ls)\nlg=sorted(lg)\nfor i in range(q):\n x=int(input())\n i1=bisect.bisect_left(ls,x)\n i2=bisect.bisect_left(lg,x)\n l1=[i1,i1+1]\n l2=[i2,i2+1]\n ans1=10**10\n ans2=10**10\n for k in l1:\n for j in l2:\n ans3=abs(x-ls[k])+abs(ls[k]-lg[j])\n if ans3<ans1:\n ans1=ans3\n ans4=abs(x-lg[j])+abs(ls[k]-lg[j])\n if ans4<ans2:\n ans2=ans4\n print(min(ans1,ans2))', 'a,b,q=map(int,input().split())\nls=[]\nfor i in range(a):\n ls.append(int(input()))\nlt=[]\nfor i in range(b):\n lt.append(int(input()))\ndef nibutan2(n,l):\n left=0\n right=len(l)-1\n mid=(right+left)//2\n while right>left:\n if l[mid]==n:\n return [0,mid]\n elif l[mid]>n:\n right=mid-1\n mid=(right+left)//2\n else:\n left=mid+1\n mid=(right+left)//2\n if min(abs(l[mid]-n),abs(l[mid-1]-n),abs(l[mid+1]-n))==abs(l[mid]-n):\n return [abs(l[mid]-n),mid]\n elif min(abs(l[mid]-n),abs(l[mid-1]-n),abs(l[mid+1]-n))==abs(l[mid-1]-n):\n return [abs(l[mid-1]-n),mid-1]\n else: \n return [abs(l[mid+1]-n),mid+1]\nfor i in range(q):\n n=int(input())\n llt=0\n lls=0\n lltl=nibutann(n,lt)\n llt1=lltl[0]\n llts=lltl[1]\n llt2=nibutann(llts,ls)[0]\n llt=llt1+llt2\n lltl=nibutann(n,ls)\n llt1=lltl[0]\n llts=lltl[1]\n llt2=nibutann(llts,lt)[0]\n lls=llt1+llt2\n print(min(llt,lls)) ', 'import bisect\na,b,q=map(int,input().split())\nls=[-10**11]\nlg=[-10**11]\nfor i in range(a):\n ls.append(int(input()))\nfor i in range(b):\n lg.append(int(input()))\nls.append(10**11)\nlg.append(10**11)\nls=sorted(ls)\nlg=sorted(lg)\nfor i in range(q):\n x=int(input())\n i1=bisect.bisect_left(ls,x)\n i2=bisect.bisect_left(lg,x)\n l1=[i1,i1+1]\n l2=[i2,i2+1]\n ans1=10**10\n ans2=10**10\n for i in l1:\n for j in l2:\n ans3=abs(x-ls[i])+abs(ls[i]-lg[j])\n if ans3<ans1:\n ans1=ans3\n ans4=abs(x-lg[j])+abs(ls[i]-lg[j])\n if ans4<ans2:\n ans2=ans4\n print(min(ans1,ans2))', 'import bisect\na,b,q=map(int,input().split())\nls=[-10**11]\nlg=[-10**11]\nfor i in range(a):\n ls.append(int(input()))\nfor i in range(b):\n lg.append(int(input()))\nls.append(10**11)\nlg.append(10**11)\nls=sorted(ls)\nlg=sorted(lg)\nfor i in range(q):\n x=int(input())\n i1=bisect.bisect_left(ls,x)\n i2=bisect.bisect_left(lg,x)\n l1=[i1-1,i1]\n l2=[i2-1,i2]\n ans1=10**12\n ans2=10**12\n for k in l1:\n for j in l2:\n ans3=abs(x-ls[k])+abs(ls[k]-lg[j])\n if ans3<ans1:\n ans1=ans3\n ans4=abs(x-lg[j])+abs(ls[k]-lg[j])\n if ans4<ans2:\n ans2=ans4\n print(min(ans1,ans2))']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s309281508', 's320433989', 's650940263', 's401357926']
[11836.0, 11072.0, 11836.0, 12168.0]
[1780.0, 357.0, 1789.0, 1762.0]
[611, 900, 611, 611]
p03112
u532966492
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['A,B,Q=map(int,input().split())\ns=[int(input()) for _ in range(A)]\nt=[int(input()) for _ in range(B)]\n\n\ndef bin_search(x,seq):\n width=[0,len(seq)-1]\n while(width[1]-width[0]>1):\n center=(sum(width)//2)\n if x>=seq[center]:\n width=[center,width[1]]\n else:\n width=[width[0],center]\nif x<=seq[width[0]]:\n return [width[0],width[0]]\nelif x>=seq[width[1]]:\n return [width[1],width[1]]\nelse:\n return width\n\nfor i in range(Q):\n x=int(input())\n Nb_s=bin_search(x,s)\n Nb_t=bin_search(x,t)\n Nb_s0=s[Nb_s[0]]\n Nb_s1=s[Nb_s[1]]\n Nb_t0=t[Nb_t[0]]\n Nb_t1=t[Nb_t[1]]\n\n k1=abs(Nb_s0-x)+abs(Nb_t0-Nb_s0)\n k2=abs(Nb_s1-x)+abs(Nb_t0-Nb_s1)\n k3=abs(Nb_s0-x)+abs(Nb_t1-Nb_s0)\n k4=abs(Nb_s1-x)+abs(Nb_t1-Nb_s1)\n k5=abs(Nb_t0-x)+abs(Nb_t0-Nb_s0)\n k6=abs(Nb_t1-x)+abs(Nb_t1-Nb_s1)\n k7=abs(Nb_t0-x)+abs(Nb_t0-Nb_s1)\n k8=abs(Nb_t1-x)+abs(Nb_t1-Nb_s0)\n print(min(k1,k2,k3,k4,k5,k6,k7,k8))', 'A,B,Q=map(int,input().split())\ns=[int(input()) for _ in range(A)]\nt=[int(input()) for _ in range(B)]\nxx=[int(input()) for _ in range(Q)]\n\n\ndef bin_search(x,seq):\n a=0\n b=len(seq)-1\n for i in range(len(seq)):\n center=((a+b)//2)\n if x>=seq[center]:\n a=center\n else:\n b=center\n if b-a<=1:\n break\n return seq[a],seq[b]\n \nfor i in range(Q):\n x=xx[i]\n Nb_s0,Nb_s1=bin_search(x,s)\n Nb_t0,Nb_t1=bin_search(x,t)\n p1=abs(Nb_s0-x)\n p2=abs(Nb_s1-x)\n p3=abs(Nb_t0-x)\n p4=abs(Nb_t1-x)\n q1=abs(Nb_t0-Nb_s0)\n q2=abs(Nb_t0-Nb_s1)\n q3=abs(Nb_t1-Nb_s0)\n q4=abs(Nb_t1-Nb_s1)\n print(min(p1+q1,p2+q2,p1+q3,p2+q4,p3+q1,p4+q4,p3+q2,p4+q3))']
['Runtime Error', 'Accepted']
['s665638560', 's167555419']
[3064.0, 16144.0]
[18.0, 1626.0]
[984, 743]
p03112
u564902833
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['from bisect import bisect_right\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nxs = [int(input()) for i in range(Q)]\nfor x in xs:\n x = int(input())\n b, d = bisect_right(s, x), bisect_right(t, x)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)\n', "from bisect import bisect_right\n\nA, B, Q = map(int, input().split())\ns = [int(input()) for _ in range(A)]\nt = [int(input()) for _ in range(B)]\nx = [int(input()) for _ in range(Q)]\n\n\nINF = 10 ** 18\nS = [-INF] + s + [INF]\nT = [-INF] + t + [INF]\n\n\n\ndef f(y):\n i = bisect_right(S, y)\n j = bisect_right(T, y)\n return min(\n abs(b - a) + min(abs(a - y), abs(b - y))\n for a in (S[i - 1], S[i])\n for b in (T[j - 1], T[j])\n )\n\n\n\nans = '\\n'.join(map(str, map(f, x)))\n\n\nprint(ans)\n"]
['Runtime Error', 'Accepted']
['s591577203', 's439959182']
[14976.0, 25476.0]
[480.0, 955.0]
[513, 672]
p03112
u581187895
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nA, B, Q = map(int, input().split())\nINF = 10**18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b = bisect.bisect_right(s, x)\n d = bisect.bisect_right(t, x)\n res = INF\n print(x, b)\n for S in [s[b-1], s[b]]:\n for T in [t[d-1], t[d]]:\n d1 = abs(S-x) + abs(T-S)\n d2 = abs(T-x) + abs(S-T)\n res = min(res, d1, d2)\n print(res)\n \n ', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10**18\nS = [-INF] + [int(input()) for i in range(A)] + [INF]\nT = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b = bisect.bisect_right(S, x)\n d = bisect.bisect_right(T, x)\n res = INF\n \n for s in [S[b-1], S[b]]:\n for t in [T[d-1], T[d]]:\n d1 = abs(s-x) + abs(t-s)\n d2 = abs(t-x) + abs(s-t)\n res = min(res, d1, d2)\n print(res)\n \n ']
['Wrong Answer', 'Accepted']
['s306710792', 's155188881']
[15748.0, 13968.0]
[1843.0, 1675.0]
[466, 455]
p03112
u585482323
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['#!usr/bin/env python3\nfrom collections import defaultdict\nfrom heapq import heappush, heappop\nimport math\nimport bisect\nimport random\ndef LI(): return list(map(int, input().split()))\ndef I(): return int(input())\ndef LS(): return input().split()\ndef S(): return list(input())\ndef IR(n): return [I() for i in range(n)]\ndef LIR(n): return [LI() for i in range(n)]\ndef SR(n): return [S() for i in range(n)]\ndef LSR(n): return [LS() for i in range(n)]\nmod = 1000000007\n\n#A\n\n#B\n\n#C\n"""\nn,a,b,c = LI()\nl = IR(n)\nf = [True for i in range(3)]\nans = 0\nfor i in range(n):\n for d in range(3):\n if abs(l[i]-[a,b,c][d]) <= 10 and f[d]:\n ans += abs(l[i]-[a,b,c][d])\n f[d] = False\n l[i] = -float("inf")\nk = False\nfor i in f:\n if i:\n k = True\n break\nif not k:\n print(ans)\n quit()\n"""\n#D\na,b,q = LI()\ns = IR(a)\nt = IR(b)\ns.insert(0,-float("inf"))\nt.insert(0,-float("inf"))\ns.append(float("inf"))\nt.append(float("inf"))\nfor i in range(q):\n x = I()\n c = bisect.bisect_left(s,x)\n ans = float("inf")\n k = abs(x-s[c-1])\n y = s[c-1]\n d = bisect.bisect_left(t,y)\n if abs(y-t[d-1]) < abs(y-t[d]):\n k += abs(y-t[d-1])\n else:\n k += abs(y-t[d])\n ans = min(k,ans)\n k = abs(x-s[c])\n y = s[c]\n d = bisect.bisect_left(t,y)\n if abs(y-t[d-1]) < abs(y-t[d]):\n k += abs(y-t[d-1])\n else:\n k += abs(y-t[d])\n ans = min(k,ans)\n c = bisect.bisect_left(t,x)\n k = abs(x-t[c-1])\n y = t[c-1]\n d = bisect.bisect_left(s,y)\n if abs(y-s[d-1]) < abs(y-s[d]):\n k += abs(y-s[d-1])\n else:\n k += abs(y-s[d])\n ans = min(k,ans)\n k = abs(x-t[c])\n y = t[c]\n d = bisect.bisect_left(s,y)\n if abs(y-s[d-1]) < abs(y-s[d]):\n k += abs(y-s[d-1])\n else:\n k += abs(y-s[d])\n ans = min(k,ans)\n print(ans)\n#E\n\n#F\n\n#G\n\n#H\n\n#I\n\n#J\n\n#K\n\n#L\n\n#M\n\n#N\n\n#O\n\n#P\n\n#Q\n\n#R\n\n#S\n\n#T\n', '#!usr/bin/env python3\nfrom collections import defaultdict\nfrom heapq import heappush, heappop\nimport sys\nimport math\nimport bisect\nimport random\ndef LI(): return list(map(int, sys.stdin.readline().split()))\ndef I(): return int(sys.stdin.readline())\ndef LS(): return sys.stdin.readline().split()\ndef S(): return list(sys.stdin.readline())\ndef IR(n): return [I() for i in range(n)]\ndef LIR(n): return [LI() for i in range(n)]\ndef SR(n): return [S() for i in range(n)]\ndef LSR(n): return [LS() for i in range(n)]\nmod = 1000000007\n\n#A\n\n#B\n\n#C\n"""\nn,a,b,c = LI()\nl = IR(n)\nf = [True for i in range(3)]\nans = 0\nfor i in range(n):\n for d in range(3):\n if abs(l[i]-[a,b,c][d]) <= 10 and f[d]:\n ans += abs(l[i]-[a,b,c][d])\n f[d] = False\n l[i] = -float("inf")\nk = False\nfor i in f:\n if i:\n k = True\n break\nif not k:\n print(ans)\n quit()\n"""\n#D\na,b,q = LI()\ns = IR(a)\nt = IR(b)\nfor i in range(q):\n x = I()\n c = bisect.bisect_left(s,x)\n ans = float("inf")\n if c == a:\n k = abs(x-s[-1])\n y = s[-1]\n d = bisect.bisect_left(t,y)\n if d == b:\n k += abs(y-t[-1])\n else:\n if abs(y-t[d-1]) < abs(y-t[d]):\n k += abs(y-t[d-1])\n else:\n k += abs(y-t[d])\n ans = min(k,ans)\n else:\n k = abs(x-s[c-1])\n y = s[c-1]\n d = bisect.bisect_left(t,y)\n if d == b:\n k += abs(y-t[-1])\n else:\n if abs(y-t[d-1]) < abs(y-t[d]):\n k += abs(y-t[d-1])\n else:\n k += abs(y-t[d])\n ans = min(k,ans)\n k = abs(x-s[c])\n y = s[c]\n d = bisect.bisect_left(t,y)\n if d == b:\n k += abs(y-t[-1])\n else:\n if abs(y-t[d-1]) < abs(y-t[d]):\n k += abs(y-t[d-1])\n else:\n k += abs(y-t[d])\n ans = min(k,ans)\n c = bisect.bisect_left(t,x)\n if c == b:\n k = abs(x-t[-1])\n y = t[-1]\n d = bisect.bisect_left(s,y)\n if d == a:\n k += abs(y-s[-1])\n else:\n if abs(y-s[d-1]) < abs(y-s[d]):\n k += abs(y-s[d-1])\n else:\n k += abs(y-s[d])\n ans = min(k,ans)\n else:\n k = abs(x-t[c-1])\n y = t[c-1]\n d = bisect.bisect_left(s,y)\n if d == a:\n k += abs(y-s[-1])\n else:\n if abs(y-s[d-1]) < abs(y-s[d]):\n k += abs(y-s[d-1])\n else:\n k += abs(y-s[d])\n ans = min(k,ans)\n k = abs(x-t[c])\n y = t[c]\n d = bisect.bisect_left(s,y)\n if d == a:\n k += abs(y-s[-1])\n else:\n if abs(y-s[d-1]) < abs(y-s[d]):\n k += abs(y-s[d-1])\n else:\n k += abs(y-s[d])\n ans = min(k,ans)\n print(ans)\n#E\n\n#F\n\n#G\n\n#H\n\n#I\n\n#J\n\n#K\n\n#L\n\n#M\n\n#N\n\n#O\n\n#P\n\n#Q\n\n#R\n\n#S\n\n#T\n']
['Wrong Answer', 'Accepted']
['s605359454', 's750026428']
[12836.0, 12960.0]
[2104.0, 1206.0]
[1907, 2960]
p03112
u607563136
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nA,B,Q = map(int,input().split())\nINF = float(\'inf\')\nS = [-INF]+[int(input()) for _ in range(A)]+[INF]\nT = [-INF]+[int(input()) for _ in range(B)]+[INF]\n\nans = []\nfor q in range(Q):\n x = int(input())\n i = bisect.bisect_right(S,x)\n j = bisect.bisect_right(T,x)\n d = INF\n for s in [S[i-1],S[i]]:\n for t in [T[i-1],T[i]]:\n d1 = abs(x-s) + abs(s-t)\n d2 = abs(x-t) + abs(s-t)\n d = min(d,d1,d2)\n ans.append(d)\nprint(*ans,sep="\\n")', 'import bisect\nA,B,Q = map(int,input().split())\nINF = float(\'inf\')\nS = [-INF]+[int(input()) for _ in range(A)]+[INF]\nT = [-INF]+[int(input()) for _ in range(B)]+[INF]\n\nans = []\nfor q in range(Q):\n x = int(input())\n i = bisect.bisect_left(S,x)\n j = bisect.bisect_left(T,x)\n d = INF\n for s in [S[i-1],S[i]]:\n for t in [T[i-1],T[i]]:\n d1 = abs(x-s) + abs(s-t)\n d2 = abs(x-t) + abs(s-t)\n d = min(d,d1,d2)\n ans.append(d)\nprint(*ans,sep="\\n")', "import bisect\nA,B,Q = map(int,input().split())\nINF = float('inf')\nS = [-INF]+[int(input()) for _ in range(A)]+[INF]\nT = [-INF]+[int(input()) for _ in range(B)]+[INF]\n\nans = []\nfor q in range(Q):\n x = int(input())\n i = bisect.bisect_right(S,x)\n j = bisect.bisect_right(T,x)\n d = INF\n for s in [S[i-1],S[i]]:\n for t in [T[i-1],T[i]]:\n d1 = abs(x-s) + abs(s-t)\n d2 = abs(x-t) + abs(s-t)\n d = min(d,d1,d2)\n ans.append(d)\nfor i in ans:\n print(i)", 'import bisect\nA,B,Q = map(int,input().split())\nINF = float(\'inf\')\nS = [-INF]+[int(input()) for _ in range(A)]+[INF]\nT = [-INF]+[int(input()) for _ in range(B)]+[INF]\n\nans = []\nfor q in range(Q):\n x = int(input())\n i = bisect.bisect_right(S,x)\n j = bisect.bisect_right(T,x)\n d = INF\n for s in [S[i-1],S[i]]:\n for t in [T[j-1],T[j]]:\n d1 = abs(x-s) + abs(s-t)\n d2 = abs(x-t) + abs(s-t)\n d = min(d,d1,d2)\n ans.append(d)\nprint(*ans,sep="\\n")']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s051628520', 's188013985', 's353127347', 's731546608']
[23920.0, 23948.0, 22092.0, 23932.0]
[928.0, 887.0, 880.0, 883.0]
[495, 493, 501, 495]
p03112
u616522759
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nprint(s,t)\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n print(b,d)\n print([s[b - 1], s[b]])\n print([t[d - 1], t[d]])\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)']
['Wrong Answer', 'Accepted']
['s593196689', 's871032243']
[22828.0, 14456.0]
[2104.0, 1733.0]
[558, 476]
p03112
u619458041
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
["import bisect\nimport sys\n\ndef main():\n input = sys.stdin.readline\n A, B, Q = map(int, input().split())\n INF = 10**18\n S = [-INF] + [int(input()) for _ in range(A)] + [INF]\n T = [-INF] + [int(inout()) for _ in range(B)] + [INF]\n \n for q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for s in [S[b-1], S[b]]:\n for t in [T[d-1], T[d]]:\n d1, d2 = abs(s-x) + abs(t-s), abs(t-x) + abs(s-t)\n res = min(res, d1, d2)\n print(res)\n\n\nif __name__ == '__main__':\n main()", "import bisect\nimport sys\n\ndef main():\n input = sys.stdin.readline\n A, B, Q = map(int, input().split())\n INF = 10**18\n S = [-INF] + [int(input()) for _ in range(A)] + [INF]\n T = [-INF] + [int(input()) for _ in range(B)] + [INF]\n \n for q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(S, x), bisect.bisect_right(T, x)\n res = INF\n for s in [S[b-1], S[b]]:\n for t in [T[d-1], T[d]]:\n d1, d2 = abs(s-x) + abs(t-s), abs(t-x) + abs(s-t)\n res = min(res, d1, d2)\n print(res)\n\n\nif __name__ == '__main__':\n main()\n"]
['Runtime Error', 'Accepted']
['s169978463', 's304323967']
[7856.0, 12800.0]
[57.0, 709.0]
[554, 557]
p03112
u619819312
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\na,b,q=map(int,input().split())\ns=[int(input())for i in range(a)]\nt=[int(input())for i in range(b)]\nfor i in range(q):\n x=int(input())\n c=bisect.bisect_left(s,x)\n d=bisect.bisect_left(t,x)\n p=[]\n if c!=a and d!=b:\n p.append(min(abs(s[c]-x),abs(t[d]-x)))\n if c!=0 and d!=0:\n p.append(min(abs(s[c-1]-x),abs(t[d-1]-x)))\n if c!=a and d!=0:\n p.append(min(abs(s[c]-x)*2+abs(t[d-1]-x),abs(s[c]-x)+2*abs(t[d-1]-x)))\n if c!=0 and d!=b\n p.append(min(abs(s[c-1]-x)*2+abs(t[d]-x),abs(s[c-1]-x)+2*abs(t[d]-x)))\n print(min(p))', 'import bisect\na,b,q=map(int,input().split())\ns=[int(input())for i in range(a)]\nt=[int(input())for i in range(b)]\nfor i in range(q):\n x=int(input())\n c=bisect.bisect_left(s,x)\n d=bisect.bisect_left(t,x)\n p=[]\n if c!=a and d!=b:\n p.append(max(abs(s[c]-x),abs(t[d]-x)))\n if c!=0 and d!=0:\n p.append(max(abs(s[c-1]-x),abs(t[d-1]-x)))\n if c!=a and d!=0:\n p.append(min(abs(s[c]-x)*2+abs(t[d-1]-x),abs(s[c]-x)+2*abs(t[d-1]-x)))\n if c!=0 and d!=b:\n p.append(min(abs(s[c-1]-x)*2+abs(t[d]-x),abs(s[c-1]-x)+2*abs(t[d]-x)))\n print(min(p))']
['Runtime Error', 'Accepted']
['s975487482', 's806461167']
[3064.0, 12092.0]
[17.0, 1652.0]
[580, 581]
p03112
u625920333
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
["import numpy as np\n\na, b, q = map(int, input().split())\nsh = []\nte = []\n\n\n\n\ndef getNearestValue(data, target):\n\n if len(data) == 0:\n return None\n if len(data) == 1:\n return data[0]\n min_diff = float('inf')\n imin = 0\n imax = len(data) - 1\n closest_num = None\n while imin <= imax:\n imid = imin + (imax - imin) // 2\n \n if imid + 1 < len(data):\n min_diff_right = abs(data[imid+1] - target)\n if imid > 0:\n min_diff_left = abs(data[imid-1] - target)\n \n if min_diff_left < min_diff:\n min_diff = min_diff_left\n closest_num = data[imid-1]\n if min_diff_right < min_diff:\n min_diff = min_diff_right\n closest_num = data[imid+1]\n \n if data[imid] < target:\n imin = imid + 1\n elif data[imid] > target:\n imax = imid - 1\n else:\n return data[imid]\n return closest_num\n\n\ndef checkshrine(x):\n x_near_sh = getNearestValue(sh, x)\n xsash = np.abs(x_near_sh - x)\n sh_near_te = getNearestValue(te, x_near_sh)\n return xsash + np.abs(sh_near_te - x_near_sh)\n\n\ndef checktemple(x):\n x_near_te = getNearestValue(te, x)\n xsate = np.abs(x_near_te - x)\n te_near_sh = getNearestValue(sh, x_near_te)\n return xsate + np.abs(te_near_sh - x_near_te)\n\n\nsh = [int(input()) for _ in range(a)]\nte = [int(input()) for _ in range(b)]\n\nfor i in range(q):\n x = int(input())\n checkshrinevalue = checkshrine(x)\n checktemplevalue = checktemple(x)\n if (checkshrinevalue > checktemplevalue):\n print(checktemplevalue)\n else:\n print(checkshrinevalue)\n", "import numpy as np\n\na, b, q = map(int, input().split())\nsh = []\nte = []\n\n\n\n\ndef getNearestValue(data, target):\n\n if len(data) == 0:\n return None\n if len(data) == 1:\n return data[0]\n min_diff = float('inf')\n imin = 0\n imax = len(data) - 1\n closest_num = None\n while imin <= imax:\n imid = imin + (imax - imin) // 2\n \n if imid + 1 < len(data):\n min_diff_right = abs(data[imid+1] - target)\n if imid > 0:\n min_diff_left = abs(data[imid-1] - target)\n \n if min_diff_left < min_diff:\n min_diff = min_diff_left\n closest_num = data[imid-1]\n if min_diff_right < min_diff:\n min_diff = min_diff_right\n closest_num = data[imid+1]\n \n if data[imid] < target:\n imin = imid + 1\n elif data[imid] > target:\n imax = imid - 1\n else:\n return data[imid]\n return closest_num\n\n\ndef checkshrine(x):\n x_near_sh = getNearestValue(sh, x)\n xsash = np.abs(x_near_sh - x)\n sh_near_te = getNearestValue(te, x_near_sh)\n return xsash + np.abs(sh_near_te - x_near_sh)\n\n\ndef checktemple(x):\n x_near_te = getNearestValue(te, x)\n xsate = np.abs(x_near_te - x)\n te_near_sh = getNearestValue(sh, x_near_te)\n return xsate + np.abs(te_near_sh - x_near_te)\n\n\nfor i in range(a):\n sh.append(int(input()))\n\nfor i in range(b):\n te.append(int(input()))\n\nfor i in range(q):\n x = int(input())\n checkshrinevalue = checkshrine(x)\n checktemplevalue = checktemple(x)\n if (checkshrinevalue > checktemplevalue):\n print(checktemplevalue)\n else:\n print(checkshrinevalue)\n", '\nimport bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s342014294', 's820678534', 's703027826']
[22360.0, 22456.0, 12812.0]
[2109.0, 2109.0, 1725.0]
[2196, 2215, 477]
p03112
u626881915
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['def find_min_fuka_idx(lst, x):\n ok = -1\n ng = len(lst)\n while abs(ok-ng)>1:\n mid = (ok+ng)//2\n if x>=lst[mid]:\n ok = mid\n else:\n ng = mid\n return ng\n\na,b,q = map(int, input().split())\ns = [-10**18]\nfor i in range(a):\n s.append(int(input()))\ns.append(10**18)\nt = [-10**18]\nfor i in range(b):\n t.append(int(input()))\nt.append(10**18)\n\nfor i in range(q):\n x = int(input())\n si = find_min_fuka_idx(s, x)\n tj = find_min_fuka_idx(t, x)\n print(min(abs(x-s[si])+abs(s[si]-t[tj]),\\\n abs(x-s[si])+abs(s[si]-t[tj-1]),\\\n abs(x-t[tj])+abs(t[tj]-s[si]),\\\n abs(x-t[tj])+abs(t[tj]-s[si-1]),\\\n abs(x-s[si-1])+abs(s[si-1]-t[tj]),\\\n abs(x-s[si-1])+abs(s[si-1]-t[tj-1]),\\\n abs(x-t[tj-1])+abs(t[tj-1]-s[si]),\\\n abs(x-t[tj]-1)+abs(t[tj-1]-s[si-1]))', 'import bisect\ndef find_min_fuka_idx(lst, x):\n ok = -1\n ng = len(lst)\n while abs(ok-ng)>1:\n mid = (ok+ng)//2\n if x>=lst[mid]:\n ok = mid\n else:\n ng = mid\n return ng\n\na,b,q = map(int, input().split())\ns = [-10**18]\ns_mid = [int(input()) for i in range(a)]\ns.extend(s_mid)\ns.append(10**18)\n\nt = [-10**18]\nt_mid = [int(input()) for i in range(b)]\nt.extend(t_mid)\nt.append(10**18)\n\nfor i in range(q):\n x = int(input())\n si = bisect.bisect_right(s, x)\n tj = bisect.bisect_right(t, x)\n print(min(abs(x-s[si])+abs(s[si]-t[tj]),\\\n abs(x-s[si])+abs(s[si]-t[tj-1]),\\\n abs(x-t[tj])+abs(t[tj]-s[si]),\\\n abs(x-t[tj])+abs(t[tj]-s[si-1]),\\\n abs(x-s[si-1])+abs(s[si-1]-t[tj]),\\\n abs(x-s[si-1])+abs(s[si-1]-t[tj-1]),\\\n abs(x-t[tj-1])+abs(t[tj-1]-s[si]),\\\n abs(x-t[tj-1])+abs(t[tj-1]-s[si-1])))\n']
['Runtime Error', 'Accepted']
['s383149264', 's501082908']
[3064.0, 13744.0]
[17.0, 1617.0]
[830, 877]
p03112
u644907318
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nA,B,Q = map(int,f.readline().split())\nS = [int(input()) for _ in range(A)]\nT = [int(input()) for _ in range(B)]\nfor _ in range(Q):\n x = int(input())\n indS = bisect.bisect_right(S,x)\n indT = bisect.bisect_right(T,x)\n if indS==0 and indT==0:\n print(max(S[0],T[0])-x)\n elif indS==0 and indT>0:\n if indT<len(T) and T[indT]<S[indS]:\n print(S[0]-x)\n elif indT<len(T) and T[indT]>S[indS]:\n r1 = T[indT]-x\n r2 = 2*(x-T[indT-1])+S[indS]-x\n r3 = x-T[ind-1]+2*(S[indS]-x)\n print(min(r1,r2,r3))\n elif indT==len(T):\n r1 = 2*(x-T[indT-1])+S[indS]-x\n r2 = x-T[indT-1]+2*(S[indS]-x)\n print(min(r1,r2))\n elif indT==0 and indS>0:\n if indS<len(S) and S[indS]<T[indT]:\n print(T[0]-x)\n elif indS<len(S) and S[indS]>T[indT]:\n r1 = S[indS]-x\n r2 = 2*(x-S[indS-1])+T[indT]-x\n r3 = x-S[indS-1]+2*(T[indT]-x)\n print(min(r1,r2,r3))\n elif indS==len(S):\n r1 = 2*(x-S[indS-1])+T[indT]-x\n r2 = x-S[indS-1]+2*(T[indT]-x)\n print(min(r1,r2))\n elif indS==len(S) and indT==len(T):\n print(x-min(S[-1],T[-1]))\n elif indS==len(S) and indT<len(T):\n if indT==0:\n r1 = 2*(x-S[-1])+T[0]-x\n r2 = x-S[-1]+2*(T[0]-x)\n print(min(r1,r2))\n elif indT>0:\n if T[indT-1]>S[-1]:\n print(x-S[-1])\n elif T[indT-1]<S[-1]:\n r1 = 2*(T[indT]-x)+x-S[-1]\n r3 = T[indT]-x+2*(x-S[-1])\n r2 = x-T[indT-1]\n print(min(r1,r2,r3))\n elif indS<len(S) and indT==len(T):\n if indS==0:\n r1 = 2*(x-T[-1])+S[0]-x\n r2 = x-T[-1]+2*(S[0]-x)\n print(min(r1,r2))\n elif indT>0:\n if S[indS-1]>T[-1]:\n print(x-T[-1])\n elif S[indS-1]<T[-1]:\n r1 = 2*(S[indS]-x)+x-T[-1]\n r3 = S[indS]-x+2*(x-T[-1])\n r2 = x-S[indt-1]\n print(min(r1,r2,r3))\n else:\n r1 = max(S[indS],T[indT])-x\n r2 = x-min(S[indS-1],T[indT-1])\n r3 = 2*(S[indS]-x)+x-T[indT-1]\n r4 = S[indS]-x+2*(x-T[indT-1])\n r5 = 2*(x-S[indS-1])+T[indT]-x\n r6 = x-S[indS-1]+2*(T[indT]-x)\n print(min(r1,r2,r3,r4,r5,r6))', 'from bisect import bisect_right\nA,B,Q = map(int,input().split())\nS = [int(input()) for _ in range(A)]\nS.append(10**11)\nS.insert(0,-10**11)\nT = [int(input()) for _ in range(B)]\nT.append(10**11)\nT.insert(0,-10**11)\nDs = {i:0 for i in range(1,A+1)}\nDs[A+1] = 10**11\nDs[0] = 10**11\nfor i in range(1,A+1):\n ind = bisect_right(T,S[i])\n Ds[i] = min(T[ind]-S[i],S[i]-T[ind-1])\nDt = {j:0 for j in range(1,B+1)}\nDt[B+1] = 10**11\nDt[0] = 10**11\nfor j in range(1,B+1):\n ind = bisect_right(S,T[j])\n Dt[j] = min(S[ind]-T[j],T[j]-S[ind-1])\nfor _ in range(Q):\n x = int(input())\n inds = bisect_right(S,x)\n cnts = min(S[inds]-x+Ds[inds],x-S[inds-1]+Ds[inds-1])\n indt = bisect_right(T,x)\n cntt = min(T[indt]-x+Dt[indt],x-T[indt-1]+Dt[indt-1])\n print(min(cnts,cntt))\n ']
['Runtime Error', 'Accepted']
['s903933127', 's443494194']
[3320.0, 38608.0]
[18.0, 1727.0]
[2388, 781]
p03112
u655975843
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nimport sys\ninput = sys.stdin.readline\na, b, q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(a)] + [INF]\nt = [-INF] + [int(input()) for i in range(b)] + [INF]\nans = []\nfor i in range(q):\n x = int(input())\n idxs = bisect.bisect(s, x)\n idxt = bisect.bisect(t, x)\n ans.append(min(x - min(s[idxs - 1], t[idxt -1]),\n x - s[idxs - 1] + (t[idxt] - s[idxs - 1]),\n t[idxt] - x + (t[idxt] - s[idxs - 1]),\n x - t[idxt - 1] + (s[idxs] - t[idxt - 1]),\n s[idxs] - x + (s[idxs] - t[idxt - 1]),\n max(s[idxs], t[idxt]) - x,\n min(x - min(s[idxs - 1], t[idxt -1]))))\nfor i in range(q):\n print(ans[i])\n\n\n\n', 'import bisect\nimport sys\ninput = sys.stdin.readline\na, b, q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(a)] + [INF]\nt = [-INF] + [int(input()) for i in range(b)] + [INF]\nans = []\nfor i in range(q):\n x = int(input())\n idxs = bisect.bisect(s, x)\n idxt = bisect.bisect(t, x)\n ans.append(min(x - min(s[idxs - 1], t[idxt -1]),\n x - s[idxs - 1] + (t[idxt] - s[idxs - 1]),\n t[idxt] - x + (t[idxt] - s[idxs - 1]),\n x - t[idxt - 1] + (s[idxs] - t[idxt - 1]),\n s[idxs] - x + (s[idxs] - t[idxt - 1]),\n max(s[idxs], t[idxt]) - x,\n min(x - min(s[idxs - 1], t[idxt -1]))\nfor i in range(q):\n print(ans[i])\n\n\n\n', "import bisect\nimport sys\ninput = sys.stdin.readline\na, b, q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(a)] + [INF]\nt = [-INF] + [int(input()) for i in range(b)] + [INF]\nans = ['' for _ in range(q)]\nfor i in range(q):\n x = int(input())\n idxs = bisect.bisect(s, x)\n idxt = bisect.bisect(t, x)\n ans[i] = str(min(x - min(s[idxs - 1], t[idxt -1]),\n x - s[idxs - 1] + (t[idxt] - s[idxs - 1]),\n t[idxt] - x + (t[idxt] - s[idxs - 1]),\n x - t[idxt - 1] + (s[idxs] - t[idxt - 1]),\n s[idxs] - x + (s[idxs] - t[idxt - 1]),\n max(s[idxs], t[idxt]) - x,\n x - min(s[idxs - 1], t[idxt -1])))\nprint('\\n'.join(ans))\n"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s966830068', 's984436816', 's180502807']
[11672.0, 3064.0, 21360.0]
[105.0, 17.0, 605.0]
[772, 770, 771]
p03112
u663230781
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['def main():\n a, b, q = map(int, input().rstrip("\\n").split(" "))\n INF = 10 ** 18\n \n jinja_list = [-INF]\n for i in range(a):\n jinja_list.append(int(input().rstrip("\\n")))\n jinja_list.append(INF)\n \n temple_list = [-INF]\n for i in range(b):\n temple_list.append(int(input().rstrip("\\n")))\n temple_list.append(INF)\n\n from bisect import bisect\n\n for i in range(q):\n pos = int(input().rstrip("\\n"))\n\n jinja_index = bisect(jinja_list, pos)\n jinja_left = jinja_list[jinja_index - 1:jinja_index]\n jinja_right = jinja_list[jinja_index:jinja_index + 1]\n\n temple_index = bisect(temple_list, pos)\n temple_left = temple_list[temple_index - 1:temple_index]\n temple_right = temple_list[temple_index:temple_index + 1]\n\n distances = []\n distances.append(pos - min(jinja_left[0], temple_left[0]))\n #distances.append("jinja_left and temple_left")\n distances.append(max(jinja_right[0], temple_right[0]) - pos)\n #distances.append("jinja_right and temple_right")\n left_right = abs(pos - jinja_left[0]) + abs(temple_right[0] - jinja_left[0])\n right_left = abs(pos - temple_right[0]) + abs(jinja_left[0] - temple_right[0])\n distances.append(left_right)\n distances.append(right_left)\n #distances.append("jinja_left and temple_right")\n left_right = abs(pos - temple_left[0]) + abs(jinja_right[0] - temple_left[0])\n right_left = abs(pos - jinja_right[0]) + abs(temple_left[0] - jinja_right[0])\n distances.append(left_right)\n distances.append(right_left)\n #distances.append("jinja_right and temple_left")\n #print(distances)\n print(min(distances))\n ', 'def main():\n a, b, q = map(int, input().rstrip("\\n").split(" "))\n INF = 10 ** 18\n \n jinja_list = [-INF]\n for i in range(a):\n jinja_list.append(int(input().rstrip("\\n")))\n jinja_list.append(INF)\n \n temple_list = [-INF]\n for i in range(b):\n temple_list.append(int(input().rstrip("\\n")))\n temple_list.append(INF)\n\n from bisect import bisect, bisect_right\n\n for i in range(q):\n pos = int(input().rstrip("\\n"))\n\n jinja_index = bisect_right(jinja_list, pos)\n jinja_left = jinja_list[jinja_index - 1]\n jinja_right = jinja_list[jinja_index]\n\n temple_index = bisect_right(temple_list, pos)\n temple_left = temple_list[temple_index - 1]\n temple_right = temple_list[temple_index]\n\n distances = []\n \n \n \n left_right = abs(pos - jinja_left) + abs(temple_left - jinja_left)\n right_left = abs(pos - temple_left) + abs(jinja_left - temple_left)\n distances.append(left_right)\n distances.append(right_left)\n \n left_right = abs(pos - jinja_right) + abs(temple_right - jinja_right)\n right_left = abs(pos - temple_right) + abs(jinja_right - temple_right)\n distances.append(left_right)\n distances.append(right_left)\n \n \n left_right = abs(pos - jinja_left) + abs(temple_right - jinja_left)\n right_left = abs(pos - temple_right) + abs(jinja_left - temple_right)\n distances.append(left_right)\n distances.append(right_left)\n left_right = abs(pos - temple_left) + abs(jinja_right - temple_left)\n right_left = abs(pos - jinja_right) + abs(temple_left - jinja_right)\n distances.append(left_right)\n distances.append(right_left)\n print(min(distances))\n ', 'def main():\n a, b, q = map(int, input().rstrip("\\n").split(" "))\n \n jinja_list = []\n \n for i in range(a):\n jinja_list.append(int(input().rstrip("\\n")))\n \n temple_list = []\n for i in range(b):\n temple_list.append(int(input().rstrip("\\n")))\n \n from bisect import bisect\n \n for i in range(q):\n pos = int(input().rstrip("\\n"))\n \n jinja_index = bisect(jinja_list, pos)\n jinja_left = jinja_list[jinja_index - 1:jinja_index]\n jinja_right = jinja_list[jinja_index:jinja_index + 1]\n \n temple_index = bisect(temple_list, pos)\n temple_left = temple_list[temple_index - 1:temple_index]\n temple_right = temple_list[temple_index:temple_index + 1]\n \n distances = []\n \n if jinja_left and temple_left:\n distances.append(pos - min(jinja_left[0], temple_left[0]))\n #distances.append("jinja_left and temple_left")\n if jinja_right and temple_right:\n distances.append(max(jinja_right[0], temple_right[0]) - pos)\n #distances.append("jinja_right and temple_right")\n if jinja_left and temple_right:\n left_right = (pos - jinja_left[0]) * 2 + (temple_right[0] - pos)\n right_left = (pos - jinja_left[0]) + (temple_right[0] - pos) * 2\n distances.append(left_right)\n distances.append(right_left)\n #distances.append("jinja_left and temple_right")\n if jinja_right and temple_left:\n left_right = ((pos - temple_left[0]) * 2) + (jinja_right[0] - pos)\n right_left = (pos - temple_left[0]) + ((jinja_right[0] - pos) * 2)\n distances.append(left_right)\n distances.append(right_left)\n #distances.append("jinja_right and temple_left")\n #print(distances)\n print(min(distances))\n\nif __name __ == \'__main__\':\n main()\n', 'def main():\n a, b, q = map(int, input().rstrip("\\n").split(" "))\n\n jinja_list = []\n\n for i in range(a):\n jinja_list.append(int(input().rstrip("\\n")))\n\n temple_list = []\n for i in range(b):\n temple_list.append(int(input().rstrip("\\n")))\n\n from bisect import bisect\n\n for i in range(q):\n pos = int(input().rstrip("\\n"))\n\n jinja_index = bisect(jinja_list, pos)\n jinja_left = jinja_list[jinja_index - 1:jinja_index]\n jinja_right = jinja_list[jinja_index:jinja_index + 1]\n\n temple_index = bisect(temple_list, pos)\n temple_left = temple_list[temple_index - 1:temple_index]\n temple_right = temple_list[temple_index:temple_index + 1]\n\n distances = []\n \n if jinja_left and temple_left:\n distances.append(pos - min(jinja_left[0], temple_left[0]))\n #distances.append("jinja_left and temple_left")\n if jinja_right and temple_right:\n distances.append(max(jinja_right[0], temple_right[0]) - pos)\n #distances.append("jinja_right and temple_right")\n if jinja_left and temple_right:\n left_right = (pos - jinja_left[0]) * 2 + (temple_right[0] - pos)\n right_left = (pos - jinja_left[0]) + (temple_right[0] - pos) * 2\n distances.append(left_right)\n distances.append(right_left)\n #distances.append("jinja_left and temple_right")\n if jinja_right and temple_left:\n left_right = ((pos - temple_left[0]) * 2) + (jinja_right[0] - pos)\n right_left = (pos - temple_left[0]) + ((jinja_right[0] - pos) * 2)\n distances.append(left_right)\n distances.append(right_left)\n #distances.append("jinja_right and temple_left")\n #print(distances)\n print(min(distances))\n ', 'def main():\n a, b, q = map(int, input().rstrip("\\n").split(" "))\n\n jinja_list = []\n\n for i in range(a):\n jinja_list.append(int(input().rstrip("\\n")))\n\n temple_list = []\n for i in range(b):\n temple_list.append(int(input().rstrip("\\n")))\n\n from bisect import bisect\n\n for i in range(q):\n pos = int(input().rstrip("\\n"))\n\n jinja_index = bisect(jinja_list, pos)\n jinja_left = jinja_list[jinja_index - 1:jinja_index]\n jinja_right = jinja_list[jinja_index:jinja_index + 1]\n\n temple_index = bisect(temple_list, pos)\n temple_left = temple_list[temple_index - 1:temple_index]\n temple_right = temple_list[temple_index:temple_index + 1]\n\n distances = []\n \n if jinja_left and temple_left:\n distances.append(pos - min(jinja_left[0], temple_left[0]))\n #distances.append("jinja_left and temple_left")\n if jinja_right and temple_right:\n distances.append(max(jinja_right[0], temple_right[0]) - pos)\n #distances.append("jinja_right and temple_right")\n if jinja_left and temple_right:\n left_right = abs(pos - jinja_left[0]) + abs(temple_right[0] - jinja_left[0])\n right_left = abs(pos - temple_right[0]) + abs(jinja_left[0] - temple_right[0])\n distances.append(left_right)\n distances.append(right_left)\n #distances.append("jinja_left and temple_right")\n if jinja_right and temple_left:\n left_right = abs(pos - temple_left[0]) + abs(jinja_right[0] - temple_left[0])\n right_left = abs(pos - jinja_right[0]) + abs(temple_left[0] - jinja_right[0])\n distances.append(left_right)\n distances.append(right_left)\n #distances.append("jinja_right and temple_left")\n #print(distances)\n print(min(distances))\n ', 'def main():\n a, b, q = map(int, input().rstrip("\\n").split(" "))\n\n jinja_list = []\n\n for i in range(a):\n jinja_list.append(int(input().rstrip("\\n")))\n\n temple_list = []\n for i in range(b):\n temple_list.append(int(input().rstrip("\\n")))\n\n from bisect import bisect\n\n for i in range(q):\n pos = int(input().rstrip("\\n"))\n\n jinja_index = bisect(jinja_list, pos)\n jinja_left = jinja_list[jinja_index - 1:jinja_index]\n jinja_right = jinja_list[jinja_index:jinja_index + 1]\n\n temple_index = bisect(temple_list, pos)\n temple_left = temple_list[temple_index - 1:temple_index]\n temple_right = temple_list[temple_index:temple_index + 1]\n\n distances = []\n \n if jinja_left and temple_left:\n distances.append(pos - max(jinja_left[0], temple_left[0]))\n #distances.append("jinja_left and temple_left")\n if jinja_right and temple_right:\n distances.append(min(jinja_right[0], temple_right[0]) - pos)\n #distances.append("jinja_right and temple_right")\n if jinja_left and temple_right:\n left_right = (pos - jinja_left[0]) * 2 + (temple_right[0] - pos)\n right_left = (pos - jinja_left[0]) + (temple_right[0] - pos) * 2\n distances.append(left_right)\n distances.append(right_left)\n #distances.append("jinja_left and temple_right")\n if jinja_right and temple_left:\n left_right = ((pos - temple_left[0]) * 2) + (jinja_right[0] - pos)\n right_left = (pos - temple_left[0]) + ((jinja_right[0] - pos) * 2)\n distances.append(left_right)\n distances.append(right_left)\n #distances.append("jinja_right and temple_left")\n #print(distances)\n print(min(distances))\n ', 'def main():\n a, b, q = map(int, input().rstrip("\\n").split(" "))\n INF = 10 ** 18\n \n jinja_list = [-INF]\n for i in range(a):\n jinja_list.append(int(input().rstrip("\\n")))\n jinja_list.append(INF)\n \n temple_list = [-INF]\n for i in range(b):\n temple_list.append(int(input().rstrip("\\n")))\n temple_list.append(INF)\n\n from bisect import bisect\n\n for i in range(q):\n pos = int(input().rstrip("\\n"))\n\n jinja_index = bisect(jinja_list, pos)\n jinja_left = jinja_list[jinja_index - 1]\n jinja_right = jinja_list[jinja_index]\n\n temple_index = bisect(temple_list, pos)\n temple_left = temple_list[temple_index - 1]\n temple_right = temple_list[temple_index]\n\n distances = []\n distances.append(pos - min(jinja_left, temple_left))\n #distances.append("jinja_left and temple_left")\n distances.append(max(jinja_right, temple_right) - pos)\n #distances.append("jinja_right and temple_right")\n left_right = abs(pos - jinja_left) + abs(temple_right - jinja_left)\n right_left = abs(pos - temple_right) + abs(jinja_left- temple_right)\n distances.append(left_right)\n distances.append(right_left)\n #distances.append("jinja_left and temple_right")\n left_right = abs(pos - temple_left) + abs(jinja_right - temple_left)\n right_left = abs(pos - jinja_right) + abs(temple_left - jinja_right)\n distances.append(left_right)\n distances.append(right_left)\n #distances.append("jinja_right and temple_left")\n #print(distances)\n print(min(distances))\n ', 'def main():\n a, b, q = map(int, input().rstrip("\\n").split(" "))\n\n jinja_list = []\n\n for i in range(a):\n jinja_list.append(int(input().rstrip("\\n")))\n\n temple_list = []\n for i in range(b):\n temple_list.append(int(input().rstrip("\\n")))\n\n from bisect import bisect\n\n for i in range(q):\n pos = int(input().rstrip("\\n"))\n\n jinja_index = bisect(jinja_list, pos)\n jinja_left = jinja_list[jinja_index - 1:jinja_index]\n jinja_right = jinja_list[jinja_index:jinja_index + 1]\n\n temple_index = bisect(temple_list, pos)\n temple_left = temple_list[temple_index - 1:temple_index]\n temple_right = temple_list[temple_index:temple_index + 1]\n\n distances = []\n \n if jinja_left and temple_left:\n distances.append(pos - min(jinja_left[0], temple_left[0]))\n #distances.append("jinja_left and temple_left")\n if jinja_right and temple_right:\n distances.append(max(jinja_right[0], temple_right[0]) - pos)\n #distances.append("jinja_right and temple_right")\n if jinja_left and temple_right:\n left_right = abs(pos - jinja_left[0]) + abs(temple_right[0] - jinja_left[0])\n right_left = abs(pos - temple_right[0]) + abs(jinja_left[0] - temple_right[0])\n distances.append(left_right)\n distances.append(right_left)\n #distances.append("jinja_left and temple_right")\n if jinja_right and temple_left:\n left_right = abs(pos - temple_left[0]) + abs(jinja_right[0] - temple_left[0])\n right_left = abs(pos - jinja_right[0]) + abs(temple_left[0] - jinja_right[0])\n distances.append(left_right)\n distances.append(right_left)\n #distances.append("jinja_right and temple_left")\n #print(distances)\n print(min(distances))\n \nif __name__ == \'__main__\':\n main()\n']
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s161992944', 's472660620', 's532560726', 's697765765', 's823999968', 's951376570', 's957640276', 's015760666']
[3064.0, 3064.0, 3064.0, 3064.0, 3064.0, 3064.0, 3064.0, 12092.0]
[18.0, 18.0, 17.0, 18.0, 18.0, 18.0, 18.0, 1712.0]
[1743, 1903, 1945, 1907, 1955, 1907, 1636, 1994]
p03112
u664796535
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
["import numpy as np\nimport bisect as bi\n\nA, B, Q = map(int, input().split(' '))\nss, tt, xx = [], [], []\nfor _ in range(A):\n ss.append(int(input()))\nfor _ in range(B):\n tt.append(int(input()))\nfor _ in range(Q):\n xx.append(int(input()))\n\ndef solve(x):\n ls = ss.index(x) if x in ss else bi.bisect_left(ss, x)-1\n rs = ls + 1\n lt = tt.index(x) if x in tt else bi.bisect_left(tt, x)-1\n rt = lt + 1\n x_ls = ss[ls]\n x_lt = tt[lt]\n x_rs = ss[rs] if rs < len(ss) else np.inf\n x_rt = tt[rt] if rt < len(tt) else np.inf\n\n return min(abs(x-x_ls) + min(abs(x_ls-x_lt), abs(x_ls-x_rt)),\n abs(x-x_rs) + min(abs(x_rs-x_lt), abs(x_rs-x_rt)),\n abs(x-x_lt) + min(abs(x_lt-x_lt), abs(x_lt-x_rt)),\n abs(x-x_rt) + min(abs(x_rt-x_ls), abs(x_rt-x_rs)))\n\nfor i in range(Q):\n print(solve(xx[i]))", "import numpy as np\n\nA, B, Q = map(int, input().split(' '))\nss, tt, xx = [], [], []\nfor _ in range(A):\n ss.append(int(input()))\nfor _ in range(B):\n tt.append(int(input()))\nfor _ in range(Q):\n xx.append(int(input()))\n\ndef solve(x):\n min_xs = ss[np.argmin([abs(s-x) for s in ss])]\n min_ts = tt[np.argmin([abs(t-x) for t in tt])]\n if (min_xs - x) * (min_ts - x) > 0:\n return max(min_ts, min_xs)\n else:\n return min_xs + min_ts + min(min_xs, min_ts)\n\n\nfor i in range(Q):\n print(solve(xx[i]))", "import numpy as np\nfrom bisect import bisect_left\n\nA, B, Q = map(int, input().split(' '))\nS = [-np.inf] + [int(input()) for _ in range(A)] + [np.inf]\nT = [-np.inf] + [int(input()) for _ in range(B)] + [np.inf]\nX = [int(input()) for _ in range(Q)]\n\ndef solve(x):\n\n Si, Ti = bisect_left(S, x), bisect_left(T, x)\n Sw, Se = abs(x-S[Si-1]), abs(x-S[Si])\n Tw, Te = abs(x-T[Ti-1]), abs(x-T[Ti])\n return min(max(Sw, Tw), max(Se, Te), 2*Tw+Se, 2*Sw+Te, 2*Se+Tw, 2*Te+Sw)\n\nfor x in X:\n print(solve(x))"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s741260797', 's849344128', 's995301938']
[26160.0, 28972.0, 25164.0]
[2109.0, 2109.0, 1043.0]
[840, 523, 506]
p03112
u684120680
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
["def search(x,r):\n low = 0\n high = len(r)-1\n mid = (low+high)//2\n while low<=high:\n rr = r[mid]-x\n ll = r[mid+1]-x\n if rr*ll<=0:\n return(abs(rr),abs(ll))\n elif r[mid]-x > 0:\n high = mid\n mid = (low+high)//2\n else:\n low = mid\n mid = (low+high)//2\n \n\na, b, q = [int(i) for i in input().split()]\ns = []\nfor i in range(a):\n\ts.append(int(input()))\nt = []\nfor i in range(b):\n\tt.append(int(input()))\nx = []\nfor i in range(q):\n\tx.append(int(input()))\n\nfor xx in x:\n\n s_l = float('inf')\n s_r = float('inf')\n if s[-1] - xx <= 0:\n s_l = abs(s[-1] - xx)\n elif s[0] - xx >= 0:\n s_r = abs(s[0] - xx)\n else:\n \ts_l,s_r=search(xx,s)\n \n t_l = float('inf')\n t_r = float('inf')\n if t[-1] - xx <= 0:\n t_l = abs(t[-1] - xx)\n elif t[0] - xx >= 0:\n t_r = abs(t[0] - xx)\n else:\n \tt_l,t_r=search(xx,t)\n \n #print(s_l,s_r,t_l,t_r)\n \n #l = max(s_l,t_l)\n #r = max(s_r,t_r)\n if s_l <= t_l:\n l = t_l\n lr = s_l*2 + t_r\n else:\n r = s_l\n lr = t_l*2 + s_r\n if s_r <= t_r:\n r = t_r\n rl = s_r*2 + t_l\n else:\n r = s_r\n lr = t_r*2 + s_l\n \n ans = min(l,r,lr,rl)\n print(ans)\n ", "def search(x,r):\n low = 0\n high = len(r)-1\n mid = (low+high)//2\n while low<=high:\n rr = r[mid]-x\n ll = r[mid+1]-x\n if rr*ll<=0:\n return(abs(rr),abs(ll))\n elif r[mid]-x > 0:\n high = mid\n mid = (low+high)//2\n else:\n low = mid\n mid = (low+high)//2\n \n\na, b, q = [int(i) for i in input().split()]\ns = []\nfor i in range(a):\n\ts.append(int(input()))\nt = []\nfor i in range(b):\n\tt.append(int(input()))\nx = []\nfor i in range(q):\n\tx.append(int(input()))\n\nfor xx in x:\n\n s_l = float('inf')\n s_r = float('inf')\n if s[-1] - xx <= 0:\n s_l = abs(s[-1] - xx)\n elif s[0] - xx >= 0:\n s_r = abs(s[0] - xx)\n else:\n \ts_l,s_r=search(xx,s)\n \n t_l = float('inf')\n t_r = float('inf')\n if t[-1] - xx <= 0:\n t_l = abs(t[-1] - xx)\n elif t[0] - xx >= 0:\n t_r = abs(t[0] - xx)\n else:\n \tt_l,t_r=search(xx,t)\n \n #print(s_l,s_r,t_l,t_r)\n \n #l = max(s_l,t_l)\n #r = max(s_r,t_r)\n if s_l <= t_l:\n l = t_l\n lr = s_l*2 + t_r\n else:\n r = s_l\n lr = t_l*2 + s_r\n if s_r <= t_r:\n r = t_r\n rl = s_r*2 + t_l\n else:\n r = s_r\n rl = t_r*2 + s_l\n \n ans = min(l,r,lr,rl)\n print(ans)\n ", "def search(x,r):\n low = 0\n high = len(r) - 1\n while low < high:\n mid = (low+high)//2\n if x < r[mid]:\n high = mid\n else:\n low = mid + 1\n return(abs(r[low-1]-x),abs(r[low]-x))\n \na, b, q = [int(i) for i in input().split()]\ns = [-float('inf')] + [int(input()) for _ in range(a)] + [float('inf')]\nt = [-float('inf')] + [int(input()) for _ in range(b)] + [float('inf')]\nx = [int(input()) for _ in range(q)]\n\nfor xx in x:\n \n s_l,s_r=search(xx,s)\n t_l,t_r=search(xx,t)\n \n if s_l <= t_l:\n l = t_l\n lr = s_l*2 + t_r\n else:\n l = s_l\n lr = t_l*2 + s_r\n if s_r <= t_r:\n r = t_r\n rl = s_r*2 + t_l\n else:\n r = s_r\n rl = t_r*2 + s_l\n \n ans = min(l,r,lr,rl)\n print(ans)\n "]
['Runtime Error', 'Runtime Error', 'Accepted']
['s173805817', 's486913107', 's329675295']
[15984.0, 16088.0, 16128.0]
[2104.0, 2104.0, 1424.0]
[1143, 1143, 717]
p03112
u686036872
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nA, B, Q = map(int, input().split())\n\na=[-float("inf")]\nb=[-float("inf")]\nfor i in range(A):\n a.append(int(input()))\nfor i in range(B):\n b.append(int(input())) \na+=[float("inf")]\nb+=[float("inf")]\n\nfor i in range(Q):\n q = int(input())\n x = bisect.bisect_left(a, q[i])\n y = bisect.bisect_left(b, q[i])\n for j in [a[x-1], a[x]]:\n for k in [b[y-1], b[y]]:\n ans1 = abs(j-q)+abs(j-k)\n ans2 = abs(k-q)+abs(j-k)\n ans = min(ans, ans1, ans2)\n print(ans)', 'import bisect\n\nA, B, Q = map(int, input().split())\n\nINF=10**18\nS=[-INF]+[int(input()) for i in range(A)]+[INF]\nT=[-INF]+[int(input()) for i in range(B)]+[INF]\n\nfor i in range(Q):\n x = int(input())\n s = bisect.bisect_left(S, x)\n t = bisect.bisect_left(T, x)\n saisyo = float("inf")\n for j in [S[s], S[s-1]]:\n for k in [T[t], T[t-1]]:\n saisyo = min(saisyo, abs(j-x)+abs(k-j), abs(k-x)+abs(j-k))\n print(saisyo)']
['Runtime Error', 'Accepted']
['s486289632', 's538396508']
[11068.0, 14176.0]
[350.0, 1711.0]
[520, 442]
p03112
u692746605
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['a,b,q=map(int, input().split())\n\ns=[-2*10**10]+[int(input()) for _ in range(a)]+[2*10**10]\nt=[-2*10**10]+[int(input()) for _ in range(b)]+[2*10**10]\nx=[int(input()) for _ in range(q)]\n\nfor i in range(q):\n j = bisect.bisect_left(s,x[i])\n al = x[i] - s[j-1]\n ar = s[j] - x[i]\n j = bisect.bisect_left(t,x[i])\n bl = x[i] - t[j-1]\n br = t[j] - x[i]\n l = min(max(al, bl), max(ar, br), 2*al+br, 2*ar+bl, 2*bl+ar, 2*br+al)\n print(l)\n', 'import bisect\n\na,b,q=map(int, input().split())\n\ns=[-2*10**10]+[int(input()) for _ in range(a)]+[2*10**10]\nt=[-2*10**10]+[int(input()) for _ in range(b)]+[2*10**10]\nx=[int(input()) for _ in range(q)]\n\nfor i in range(q):\n j = bisect.bisect_left(s,x[i])\n al = x[i] - s[j-1]\n ar = s[j] - x[i]\n j = bisect.bisect_left(t,x[i])\n bl = x[i] - t[j-1]\n br = t[j] - x[i]\n l = min(max(al, bl), max(ar, br), 2*al+br, 2*ar+bl, 2*bl+ar, 2*br+al)\n print(l)\n']
['Runtime Error', 'Accepted']
['s252862222', 's478919334']
[14972.0, 16132.0]
[503.0, 938.0]
[433, 448]
p03112
u708255304
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nA, B, Q = map(int, input().split()) \nINF = 10 ** 18\nshrines = [-INF] + [int(input()) for _ in range(A)] + [INF]\ntemples = [-INF] + [int(input()) for _ in range(B)] + [INF]\nX = [int(input()) for _ in range(Q)]\n\n\n\n\nshrines.sort() \ntemples.sort() \nfor x in X:\n tmp = 10**18\n\n s_right_index = bisect.bisect_right(shrines, x) \n s_left_index = bisect.bisect_right(shrines, x)-1 \n t_right_index = bisect.bisect_right(temples, x) \n t_left_index = bisect.bisect_right(temples, x)-1 \n\n \n tmp = min(tmp, max(shrines[s_right_index], temples[t_right_index])-x)\n\n \n tmp = min(tmp, abs((shrines[s_right_index]-x)) * 2 + abs(temples[t_left_index]))\n\n \n tmp = min(tmp, abs((temples[t_right_index]-x)) * 2 + abs(shrines[s_left_index]))\n\n \n tmp = min(tmp, abs((temples[t_left_index]-x)) * 2 + abs(shrines[s_right_index]))\n\n \n tmp = min(tmp, abs((shrines[s_left_index]-x)) * 2 + abs(temples[t_left_index]))\n\n \n tmp = min(tmp, abs(x - min(abs(shrines[s_left_index]), abs(temples[t_left_index]))))\n\n print(tmp)\n', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for _ in range(A)] + [INF]\nt = [-INF] + [int(input()) for _ in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n \n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n res = INF\n for S in [s[b-1], s[b]]: \n for T in [t[d-1], t[d]]: \n d1, d2 = abs(S-x) + abs(T-S), abs(T-x) + abs(S-T) \n res = min(res, d1, d2)\n print(res)\n']
['Wrong Answer', 'Accepted']
['s405649119', 's013510200']
[16144.0, 14080.0]
[1149.0, 1694.0]
[1723, 628]
p03112
u720636500
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nA, B, Q = map(int, input().split())\ninf = 10**18\nlisS = [-inf] + [int(input(x)) for x in range(A)] + [inf]\nlisT = [-inf] + [int(input(x)) for x in range(B)] + [inf]\nfor _ in range(Q):\n x = int(input())\n i = bisect.bisect_right(lisS, x)\n j = bisect.bisect_right(lisT, x)\n res = inf\n for S in [lisS[i - 1], lisS[i]]:\n for T in [lisT[j - 1], lisT[j]]:\n r1 = abs(S - x) + abs(S - T)\n r2 = abs(T - x) + abs(S - T)\n res = min(res, r1, r2)\n print(res)', 'import bisect\nA, B, Q = map(int, input().split())\ninf = 10**18\nlisS = [-inf] + [int(input(x)) for x in range(A)] + [inf]\nlisT = [-inf] + [int(input(x)) for x in range(B)] + [inf]\nfor _ in range(Q):\n x = int(input())\n i, j = bisect.bisect_right(lisS, x), bisect.bisect_right(lisT, x)\n res = inf\n for S in [lisS[i - 1], lisS[i]]:\n for T in [lisT[j - 1], lisT[j]]:\n r1, r2 = abs(S - x) + abs(S - T), abs(T - x) + abs(S - T)\n res = min(res, r1, r2)\n print(res)', 'import bisect\nA, B, Q = map(int, input().split())\nlisS = [int(input(x)) for x in range(A)]\nlisT = [int(input(x)) for x in range(B)]\nlisQ = [int(input(x)) for x in range(Q)]\nfor x in lisQ:\n i = bisect.bisect_right(lisS, x)\n j = bisect.bisect_right(lisT, x)\n if i >= A:\n SR = 10**12\n else:\n SR = lisS[i] - x\n SL = x - lisS[i - 1] \n if j >= B:\n TR = 10**12\n else:\n TR = lisT[j] - x\n TL = x - lisT[j - 1]\n r1 = SR + abs(SR - TR)\n r2 = 2*SR + TL\n r3 = SL + abs(SL - TL)\n r4 = 2*SL + TR\n r5 = TR + abs(TR - SR)\n r6 = 2*TR + SL\n r7 = TL + abs(TL - SL)\n r8 = 2*TL + SR\n print(min(r1, r2, r3, r4, r5, r6, r7, r8))', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n\u3000\u3000x = int(input())\n\u3000\u3000b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n\u3000\u3000res = INF\n\u3000\u3000for S in [s[b - 1], s[b]]:\n\u3000\u3000\u3000\u3000for T in [t[d - 1], t[d]]:\n\u3000\u3000\u3000\u3000\u3000\u3000d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n\u3000\u3000\u3000\u3000\u3000\u3000res = min(res, d1, d2)\nprint(res)', 'import bisect\nA, B, Q = map(int, input().split())\ninf = 10**18\nlisS = [-inf] + [int(input()) for x in range(A)] + [inf]\nlisT = [-inf] + [int(input()) for x in range(B)] + [inf]\nfor _ in range(Q):\n x = int(input())\n i = bisect.bisect_right(lisS, x)\n j = bisect.bisect_right(lisT, x)\n res = inf\n for S in [lisS[i - 1], lisS[i]]:\n for T in [lisT[j - 1], lisT[j]]:\n r1 = abs(S - x) + abs(S - T)\n r2 = abs(T - x) + abs(S - T)\n res = min(res, r1, r2)\n print(res)']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s027769261', 's100286761', 's557136504', 's640598072', 's614803814']
[13444.0, 14848.0, 17648.0, 2940.0, 12800.0]
[2104.0, 2104.0, 2105.0, 17.0, 1675.0]
[482, 474, 634, 496, 480]
p03112
u726615467
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['A, B, Q = map(int, input().split())\ns = [int(input()) for _ in range(A)]\nt = [int(input()) for _ in range(B)]\nx = [int(input()) for _ in range(Q)]\ninf = 10 ** 18\n\ns = [-inf] + s + [inf]\nt = [-inf] + t + [inf]\n\ndef binsearch_l(seq, l, r, tar):\n if r - l < 2: return l\n #\n m = l + (r - l) // 2\n # print("##", l, r, (m, seq[m]), tar)\n if seq[m] <= tar:\n return binsearch_l(seq, m, r, tar)\n else:\n return binsearch_l(seq, l, m - 1, tar)\n\nfor x_tmp in x:\n i_l = binsearch_l(s, 0, A + 2, x_tmp)\n j_l = binsearch_l(t, 0, B + 2, x_tmp)\n #\n ans = inf\n for i, j in ((i_l, j_l), (i_l + 1, j_l), (i_l, j_l + 1), (i_l + 1, j_l + 1)):\n if i < 1 or A < i: continue\n if j < 1 or B < j: continue\n ans_tmp_s = abs(x_tmp - s[i]) + abs(s[i] - t[j])\n ans_tmp_t = abs(x_tmp - t[j]) + abs(s[i] - t[j])\n ans_tmp = min(ans_tmp_s, ans_tmp_t)\n # print("#", x_tmp, s[i], t[j], ans_tmp)\n if ans > ans_tmp:\n ans = ans_tmp\n #\n print(ans)', 'A, B, Q = map(int, input().split())\n\nMY_INF = 10 ** 18\n\ns = [int(input()) for _ in range(A)]\nt = [int(input()) for _ in range(B)]\nx = [int(input()) for _ in range(Q)]\n\ns = [-MY_INF] + s + [MY_INF]\nt = [-MY_INF] + t + [MY_INF]\n\nimport bisect\n\nfor i, xi in enumerate(x):\n ans = 10 ** 18\n #\n \n idx_s = bisect.bisect_left(s, xi)\n #\n s_l = s[idx_s - 1]\n idx_tl = bisect.bisect_left(t, s_l)\n #\n t_ll = t[idx_tl - 1]\n ans_tmp = abs(s_l - xi) + abs(t_ll - s_l)\n ans = min(ans, ans_tmp)\n t_lr = t[idx_tl]\n ans_tmp = abs(s_l - xi) + abs(t_lr - s_l)\n ans = min(ans, ans_tmp)\n #\n s_r = s[idx_s]\n idx_tr = bisect.bisect_left(t, s_r)\n #\n t_rl = t[idx_tr - 1]\n ans_tmp = abs(s_r - xi) + abs(t_rl - s_r)\n ans = min(ans, ans_tmp)\n #\n t_rr = t[idx_tr]\n ans_tmp = abs(s_r - xi) + abs(t_rr - s_r)\n ans = min(ans, ans_tmp)\n #\n # t -> r\n idx_t = bisect.bisect_left(t, xi)\n #\n t_l = t[idx_t - 1]\n idx_sl = bisect.bisect_left(s, t_l)\n #\n s_ll = s[idx_sl - 1]\n ans_tmp = abs(t_l - xi) + abs(s_ll - t_l)\n ans = min(ans, ans_tmp)\n s_lr = s[idx_sl]\n ans_tmp = abs(t_l - xi) + abs(s_lr - t_l)\n ans = min(ans, ans_tmp)\n #\n t_r = t[idx_t]\n idx_sr = bisect.bisect_left(s, t_r)\n #\n s_rl = s[idx_sr - 1]\n ans_tmp = abs(t_r - xi) + abs(s_rl - t_r)\n ans = min(ans, ans_tmp)\n #\n s_rr = s[idx_sr]\n ans_tmp = abs(t_r - xi) + abs(s_rr - t_r)\n ans = min(ans, ans_tmp)\n #\n print(ans)\n']
['Wrong Answer', 'Accepted']
['s550183103', 's041637849']
[16760.0, 16784.0]
[2104.0, 1535.0]
[1019, 1503]
p03112
u729133443
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
["from bisect import*\na,b,q,*l=map(int,open(0).read().split())\nif a==2and b==3and q==4:\n print('hoge')\nf=10**18\ns,t=[-f]+l[:a]+[f],[-f]+l[a:a+b]+[f]\nfor x in l[a+b:]:\n m=f\n i=bisect(s,x)\n j=bisect(t,x)\n for k in[i,i-1]:\n for l in[j,j-1]:\n m=min(m,abs(x-s[k])+abs(s[k]-t[l]),abs(x-t[l])+abs(t[l]-s[k]))\n print(m)", 'a,b,q=map(int,input().split())\ns=[int(input())for i in range(a)]\nt=[int(input())for i in range(b)]\nx=[int(input())for i in range(q)]', "from bisect import*\na,b,q,*l=map(int,open(0).read().split())\nif a==2and b==3and q==4:\n print('hoge')\nf=10**18\ns,t=[-f]+l[:a]+[f],[-f]+l[a:a+b]+[f]\nfor x in l[a+b:]:\n m=f\n i=bisect(s,x)\n j=bisect(t,s[i])\n k=bisect(t,s[i-1])\n v=abs(x-s[i])+abs(s[i]-t[k])\n if v<m:m=v\n v=abs(x-t[k])+abs(t[k]-s[i])\n if v<m:m=v\n v=abs(x-s[i])+abs(s[i]-t[k-1])\n if v<m:m=v\n v=abs(x-t[k-1])+abs(t[k-1]-s[i])\n if v<m:m=v \n v=abs(x-s[i-1])+abs(s[i-1]-t[k])\n if v<m:m=v\n v=abs(x-t[k])+abs(t[k]-s[i-1])\n if v<m:m=v\n v=abs(x-s[i-1])+abs(s[i-1]-t[k-1])\n if v<m:m=v\n v=abs(x-t[k-1])+abs(t[k-1]-s[i-1])\n if v<m:m=v\n i=bisect(t,x)\n j=bisect(s,t[i])\n k=bisect(s,t[i-1])\n v=abs(x-t[i])+abs(t[i]-s[k])\n if v<m:m=v\n v=abs(x-s[k])+abs(s[k]-t[i])\n if v<m:m=v \n v=abs(x-t[i])+abs(t[i]-s[k-1])\n if v<m:m=v\n v=abs(x-s[k-1])+abs(s[k-1]-t[i])\n if v<m:m=v \n v=abs(x-t[i-1])+abs(t[i-1]-s[k])\n if v<m:m=v\n v=abs(x-s[k])+abs(s[k]-t[i-1])\n if v<m:m=v\n v=abs(x-t[i-1])+abs(t[i-1]-s[k-1])\n if v<m:m=v\n v=abs(x-s[k-1])+abs(s[k-1]-t[i-1])\n if v<m:m=v\n print(m)", 'from bisect import*\nA,B=abs,bisect\na,b,q,*l=map(int,open(0).read().split())\nf=2**60\ns,t=[-f]+l[:a]+[f],[-f]+l[a:a+b]+[f]\nfor x in l[a+b:]:\n m=f\n i,j=B(s,x),B(t,x)\n for v in s[i-1,i+1]:\n for w in t[j-1,j+1]:\n m=min(m,A(x-v)+A(v-w),A(x-w)+A(w-v))\n print(m)', "from bisect import*\na,b,q,*l=map(int,open(0).read().split())\nif a==2and b==3and q==4:\n print('hoge')\nf=10**18\ns,t=[-f]+l[:a]+[f],[-f]+l[a:a+b]+[f]\nfor x in l[a+b:]:\n m=f\n i=bisect(s,x)\n j=bisect(t,s[i])\n k=bisect(t,s[i-1])\n v=abs(x-s[i])+abs(s[i]-t[k])\n if v<m:m=v\n v=abs(x-s[i])+abs(s[i]-t[k-1])\n if v<m:m=v\n v=abs(x-s[i-1])+abs(s[i-1]-t[k])\n if v<m:m=v\n v=abs(x-s[i-1])+abs(s[i-1]-t[k-1])\n if v<m:m=v\n i=bisect(t,x)\n j=bisect(s,t[i])\n k=bisect(s,t[i-1])\n v=abs(x-t[i])+abs(t[i]-s[k])\n if v<m:m=v\n v=abs(x-t[i])+abs(t[i]-s[k-1])\n if v<m:m=v\n v=abs(x-t[i-1])+abs(t[i-1]-s[k])\n if v<m:m=v\n v=abs(x-t[i-1])+abs(t[i-1]-s[k-1])\n if v<m:m=v\n print(m)", 'from bisect import*\nA,B=abs,bisect\na,b,q,*l=map(int,open(0).read().split())\nf=2**60\ns,t=[-f]+l[:a]+[f],[-f]+l[a:a+b]+[f]\nfor x in l[a+b:]:\n m=f\n i,j=B(s,x),B(t,x)\n for v in s[i-1:i+1]:\n for w in t[j-1:j+1]:\n m=min(m,A(x-v)+A(v-w),A(x-w)+A(w-v))\n print(m)']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s178313709', 's365856431', 's421843151', 's766070387', 's992168165', 's754350872']
[36604.0, 15012.0, 36340.0, 38620.0, 36316.0, 38660.0]
[803.0, 486.0, 1313.0, 96.0, 916.0, 778.0]
[323, 132, 1049, 266, 670, 266]
p03112
u734548018
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['# -*- coding: utf-8 -*-\nimport math\nimport sys\nimport bisect\n\n## input\na,b,q = map(int, sys.stdin.readline().rstrip().split())\ns_s, t_s, x_s = [[], [], []]\nfor _ in range(a):\n s_s.append(int(sys.stdin.readline().rstrip()))\nfor _ in range(b):\n t_s.append(int(sys.stdin.readline().rstrip()))\nfor _ in range(q):\n x_s.append(int(sys.stdin.readline().rstrip()))\n\n\n## solve\ndef get_otherlen(st_s, k):\n idx = bisect.bisect_left(st_s, k)\n if idx == 0:\n mn = abs(st_s[0]-k)\n elif idx == len(s_s):\n mn = abs(st_s[-1]-k)\n else:\n mn = min(abs(st_s[idx]-k), abs(st_s[idx-1]-k))\n return(mn)\n\n\ndef get_len(k):\n \n idx = bisect.bisect_left(s_s, k)\n if idx == 0:\n mn = abs(s_s[0]-k) + get_otherlen(t_s, s_s[0])\n elif idx == len(s_s):\n mn = abs(s_s[-1]-k) + get_otherlen(t_s, s_s[-1])\n else:\n mn1 = abs(s_s[idx]-k) + get_otherlen(t_s, s_s[idx])\n mn2 = abs(s_s[idx-1]-k) + get_otherlen(t_s, s_s[idx-1])\n mn = min(mn1, mn2)\n\n # t -> s\n idx = bisect.bisect_left(t_s, k)\n if idx == 0:\n mn = min(mn, abs(t_s[0]-k) + get_otherlen(s_s, t_s[0]))\n elif idx == len(t_s):\n mn = min(mn, abs(t_s[-1]-k) + get_otherlen(s_s, t_s[-1]))\n else:\n mn1 = abs(t_s[idx]-k) + get_otherlen(s_s, t_s[idx])\n mn2 = abs(t_s[idx-1]-k) + get_otherlen(s_s, t_s[idx-1])\n mn = min(mn, mn1, mn2)\n return(mn)\n\n\nif __name__ == "__main__":\n for x in x_s:\n print(x, get_len(x))', '# -*- coding: utf-8 -*-\nimport math\nimport sys\nimport bisect\n\n## input\na,b,q = map(int, sys.stdin.readline().rstrip().split())\ns_s, t_s, x_s = [[-10**11], [-10**11], []]\nfor _ in range(a):\n s_s.append(int(sys.stdin.readline().rstrip()))\nfor _ in range(b):\n t_s.append(int(sys.stdin.readline().rstrip()))\nfor _ in range(q):\n x_s.append(int(sys.stdin.readline().rstrip()))\ns_s.append(10**11)\nt_s.append(10**11)\n\n\ndef solve(k):\n s_pos = bisect.bisect_left(s_s, k)\n t_pos = bisect.bisect_left(t_s, k)\n mn = 10**11\n for i in [s_s[s_pos-1], s_s[s_pos]]:\n for j in [t_s[t_pos-1], t_s[t_pos]]:\n mn = min(mn,abs(i-k)+abs(i-j), abs(j-k)+abs(i-j))\n return(mn)\n\nif __name__ == "__main__":\n for x in x_s:\n print(solve(x))']
['Runtime Error', 'Accepted']
['s808977515', 's711896198']
[17244.0, 16168.0]
[1166.0, 846.0]
[1389, 728]
p03112
u739362834
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['A, B, Q = map(int, input().split())\ns = []\nfor i in range(A):\n s.append(int(input()))\ns.sort()\nt = []\nt.sort()\nfor i in range(B):\n t.append(int(input()))\nx = []\nfor i in range(Q):\n x.append(int(input()))\n\nfor i in range(Q):\n sx, tx, sy, ty = [], [], [], []\n for j in range(A):\n sx.append(abs(s[j] - x[i]))\n for j in range(B):\n tx.append(abs(t[j] - x[i]))\n sxi = sx.index(min(sx))\n txi = tx.index(min(tx))\n for j in range(B):\n ty.append(abs(t[j] - s[sxi]))\n for j in range(A):\n sy.append(abs(s[j] - t[sxi]))\n a = min(sx) + min(ty)\n b = min(tx) + min(sy)\n if a < b:\n print(a)\n else:\n print(b)\n', 'A, B, Q = map(int, input().split())\ns = []\nfor i in range(A):\n s.append(int(input()))\ns.sort()\nt = []\nt.sort()\nfor i in range(B):\n t.append(int(input()))\nx = []\nfor i in range(Q):\n x.append(int(input()))\n\nfor i in range(Q):\n sx, tx, sy, ty = [], [], [], []\n for j in range(A):\n sx.append(abs(s[j] - x[i]))\n for j in range(B):\n tx.append(abs(t[j] - x[i]))\n sxi = sx.index(min(sx))\n txi = tx.index(min(tx))\n for j in range(B):\n ty.append(abs(t[j] - s[sxi]))\n for j in range(A):\n sy.append(abs(s[j] - t[sxi]))\n a = min(sx) + min(ty)\n b = min(tx) + min(sy)\n if a < b:\n print("a"+str(a))\n else:\n print("b"+str(b))\n', 'import bisect\n\nA, B, Q = map(int, input().split())\nINF = 10**18\nS = [-INF]\nfor i in range(A):\n S.append(int(input()))\nS.append(INF)\nT = [-INF]\nfor i in range(B):\n T.append(int(input()))\n T.append(INF)\nX = []\nfor i in range(Q):\n X.append(int(input()))\n\nfor x in X:\n ids, idt = bisect.bisect_right(S, x), bisect.bisect_right(T, x)\n print(min(abs(s-t) + min(abs(s-x), abs(t-x))\n for s in S[ids-1:ids+1] for t in T[idt-1:idt+1]))\n', 'import bisect\n\nA, B, Q = map(int, input().split())\nINF = 10**18\nS = [-INF]\nfor i in range(A):\n S.append(int(input()))\nS.append(INF)\nT = [-INF]\nfor i in range(B):\n T.append(int(input()))\nT.append(INF)\nX = []\nfor i in range(Q):\n X.append(int(input()))\n\nfor x in X:\n a, b = bisect.bisect_right(S, x), bisect.bisect_right(T, x)\n print(min(abs(s-t) + min(abs(s-x), abs(t-x))\n for s in S[a-1:a+1] for t in T[b-1:b+1]))\n']
['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s122005226', 's157196093', 's998228964', 's998376420']
[30876.0, 30876.0, 16932.0, 16160.0]
[2106.0, 2106.0, 1137.0, 1140.0]
[675, 693, 457, 441]
p03112
u763115743
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\n\n\ndef solve(a_list, b_list, position):\n # time O(log(A))\n a_right_key = bisect.bisect_left(a_list, position)\n a_left_key = a_right_key - 1\n \n b_right_key = bisect.bisect_left(b_list, position)\n b_left_key = b_right_key - 1\n\n a_left, a_right = a_list[a_left_key], a_list[a_right_key]\n b_left, b_right = b_list[b_left_key], b_list[b_right_key]\n\n ans = 10 ** 20\n for a_position in [a_left, a_right]:\n for b_position in [b_left, b_right]:\n distance1 = abs(position - a_position) + abs(a_position - b_position)\n distance2 = abs(position - b_position) + abs(a_position - b_position)\n ans = min(ans, distance1, distance2)\n return ans\n\n\ndef main():\n inf = 10 ** 20\n A, B, Q = map(int, input().split())\n\n # time O(A)\n a_list = [int(input()) for _ in range(A)]\n a_list = [-inf] + a_list + [inf]\n \n b_list = [int(input()) for _ in range(A)]\n b_list = [-inf] + b_list + [inf]\n\n \n for _ in range(Q):\n position = int(input())\n ans = solve(a_list, b_list, position)\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n', 'import bisect\n\n\ndef solve(a_list, b_list, position):\n # time O(log(A))\n a_right_key = bisect.bisect_left(a_list, position)\n a_left_key = a_right_key - 1\n \n b_right_key = bisect.bisect_left(b_list, position)\n b_left_key = b_right_key - 1\n\n a_left, a_right = a_list[a_left_key], a_list[a_right_key]\n b_left, b_right = b_list[b_left_key], b_list[b_right_key]\n\n ans = 10 ** 20\n for a_position in [a_left, a_right]:\n for b_position in [b_left, b_right]:\n distance1 = abs(position - a_position) + abs(a_position - b_position)\n distance2 = abs(position - b_position) + abs(a_position - b_position)\n ans = min(ans, distance1, distance2)\n return ans\n\n\ndef main():\n inf = 10 ** 20\n A, B, Q = map(int, input().split())\n\n # time O(A)\n a_list = [int(input()) for _ in range(A)]\n a_list = [-inf] + a_list + [inf]\n \n b_list = [int(input()) for _ in range(B)]\n b_list = [-inf] + b_list + [inf]\n\n \n for _ in range(Q):\n position = int(input())\n ans = solve(a_list, b_list, position)\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n']
['Runtime Error', 'Accepted']
['s575280017', 's723328423']
[13564.0, 13584.0]
[1628.0, 1636.0]
[1196, 1196]
p03112
u785578220
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect.bisect_right from bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n #print(b,d)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)', 'import sys\nfrom bisect import bisect_right \nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [sys.stdin.readline() for i in range(A)] + [INF]\nt = [-INF] + [sys.stdin.readline() for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect_right(s, x), bisect_right(t, x)\n #print(b,d)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)\n', 'import sys\nfrom bisect import bisect.bisect_right \nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [sys.stdin.readline() for i in range(A)] + [INF]\nt = [-INF] + [sys.stdin.readline() for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n #print(b,d)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)\n\n', '\nimport bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n print(b,d)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)\n\n', 'from bisect import bisect.bisect_right\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n #print(b,d)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)\n', 'import bisect\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nfor q in range(Q):\n x = int(input())\n b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)\n #print(b,d)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s178031688', 's373046525', 's517597455', 's761567006', 's765113882', 's616504191']
[2940.0, 18064.0, 2940.0, 13840.0, 2940.0, 14464.0]
[17.0, 104.0, 17.0, 1921.0, 17.0, 1760.0]
[517, 525, 547, 494, 518, 493]
p03112
u794543767
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import itertools\nA,B,Q = [int(_) for _ in input().split(" ")]\ns = [int(input()) for _ in range(A)]\nt = [int(input()) for _ in range(B)] \nx = [int(input()) for _ in range(Q)]\n\ndef binary_search(arr,point,start,end):\n pivot = (start+end)//2\n if end -start > 1:\n if arr[pivot] <point :\n return binary_search(arr,point,pivot,end)\n else:\n return binary_search(arr,point,start,pivot)\n else:\n return start\n \ndef find_closest_path(s_1,s_2,t_1,t_2,point):\n shortest = 10**11\n for s,t in itertools.product([s_1,s_2],[t_1,t_2]):\n length = min(abs(point-t), abs(point -s )) + abs(s - t)\n if length < shortest:\n shortest = length \n return length \n\n\nfor i in range(Q):\n s_idx = binary_search(s,x[i],0,len(s)-1)\n t_idx = binary_search(t,x[i],0,len(t)-1)\n if len(s)>1:\n s_1,s_2 = s[s_idx],s[s_idx+1] \n else:\n s_1,s_2 = s[0],s[0]\n if len(t)>1:\n t_1,t_2 = t[t_idx],t[t_idx+1] \n else:\n t_1,t_2 = t[0],t[0]\n answer = find_closest_path(s_1,s_2,t_1,t_2,x[i])\n print(answer)', 'import itertools\nA,B,Q = [int(_) for _ in input().split(" ")]\ns_array = [int(input()) for _ in range(A)]\nt_array = [int(input()) for _ in range(B)] \nx = [int(input()) for _ in range(Q)]\n\ndef binary_search(arr,point,start,end):\n pivot = (start+end)//2\n if end -start > 1:\n if arr[pivot] <point :\n return binary_search(arr,point,pivot,end)\n else:\n return binary_search(arr,point,start,pivot)\n else:\n return start\n \ndef find_closest_path(s_1,s_2,t_1,t_2,point):\n shortest = 10**11\n for s,t in itertools.product([s_1,s_2],[t_1,t_2]):\n length = min(abs(point-t), abs(point -s )) + abs(s - t)\n if length < shortest:\n shortest = length \n return shortest \n\n\nfor i in range(Q):\n s_idx = binary_search(s_array,x[i],0,len(s_array)-1)\n t_idx = binary_search(t_array,x[i],0,len(t_array)-1)\n if len(s_array)>1:\n s_1,s_2 = s_array[s_idx],s_array[s_idx+1] \n else:\n s_1,s_2 = s_array[0],s_array[0]\n if len(t_array)>1:\n t_1,t_2 = t_array[t_idx],t_array[t_idx+1] \n else:\n t_1,t_2 = t_array[0],t_array[0]\n answer = find_closest_path(s_1,s_2,t_1,t_2,x[i])\n print(answer)\n\n\n\n\n\n\n']
['Wrong Answer', 'Accepted']
['s702340576', 's740120426']
[16176.0, 16176.0]
[1918.0, 1969.0]
[1144, 1249]
p03112
u807772568
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\na,b,c = map(int,input().split())\n\naa = []\nbb = []\nfor i in range(a):\n\taa.append(int(input()))\nfor i in range(b):\n\tbb.append(int(input()))\nfor i in range(c):\n\tcc = int(input())\n\taaa = bisect.bisect_left(aa,cc)\n\tbbb = bisect.bisect_left(bb,cc)\n\tif aaa == 0 and bbb == 0:\n\t\tprint(max(aa[0],bb[0]) - cc)\n\telif aaa == a and bbb == b:\n\t\tprint(cc - min(aa[a-1],bb[b-1]))\n\telif aaa == 0:\n\t\tif bbb == b:\n\t\t\tprint(min(abs(cc - aa[0]),abs(cc - bb[bbb-1])) + aa[0] - bb[bbb-1])\n\t\telse:\n\t\t\taaaa = min(abs(bb[bbb] - aa[0]),abs(bb[bbb-1] - aa[0]))\n\t\t\tprint(min(abs(cc - aa[0]),abs(cc - bb[bbb-1]),abs(cc - bb[bbb])) + aaaa)\n\telif bbb == 0:\n\t\tif aaa == a:\n\t\t\tprint(min(abs(cc - aa[0]),abs(cc - bb[bbb-1])) + bb[0] - aa[aaa-1])\n\t\telse:\n\t\t\tbbbb = min(abs(bb[0] - aa[aaa-1]),abs(bb[0] - aa[aaa]))\n\t\t\tprint(min(abs(cc - bb[0]),abs(cc - aa[aaa-1]),abs(cc - aa[aaa])) + bbbb)\n\telif aaa == a:\n\t\taaaa = min(abs(bb[bbb] - aa[a-1])+min(abs(cc-aa[a-1]),abs(cc-bb[bbb])),abs(bb[bbb-1] - aa[a-1])+min(abs(cc-aa[a-1]),abs(cc-bb[bbb-1])))\n\t\tprint(aaaa)\n\telif bbb == b:\n\t\tbbbb = min(abs(bb[b-1] - aa[aaa-1])+min(abs(cc-aa[aaa-1]),abs(cc-bb[b-1])),abs(bb[b-1] - aa[aaa])+min(abs(cc-aa[aaa]),abs(cc-bb[b-1])))\n\t\tprint(abs(cc - bb[b-1]) + bbbb)\n\telse:\n\t\taaaa = min(max(aa[aaa],bb[bbb])-cc,cc-min(aa[aaa-1],bb[bbb-1]),2*aa[aaa] - cc - bb[bbb-1],aa[aaa] + cc - 2 * bb[bbb-1])\n\t\tprint(aaaa)', '\nimport bisect\na,b,c = map(int,input().split())\n\naa = []\nbb = []\nfor i in range(a):\n\taa.append(int(input()))\nfor i in range(b):\n\tbb.append(int(input()))\nfor i in range(c):\n\tcc = int(input())\n\taaa = bisect.bisect_left(aa,cc)\n\tbbb = bisect.bisect_left(bb,cc)\n\tif aaa == 0 and bbb == 0:\n\t\tprint(max(aa[0],bb[0]) - cc)\n\telif aaa == a and bbb == b:\n\t\tprint(cc - min(aa[a-1],bb[b-1]))\n\telif aaa == 0:\n\t\tif bbb == b:\n\t\t\tprint(min(abs(cc - aa[0]),abs(cc - bb[bbb-1])) + aa[0] - bb[bbb-1])\n\t\telse:\n\t\t\taaaa = min(abs(bb[bbb] - aa[0])min(abs(cc-aa[0]),abs(cc-bb[bbb])),abs(bb[bbb-1] - aa[0])min(abs(cc-aa[a-1]),abs(cc-bb[bbb-1])))\n\t\t\tprint(aaaa)\n\telif bbb == 0:\n\t\tif aaa == a:\n\t\t\tprint(min(abs(cc - aa[0]),abs(cc - bb[bbb-1])) + bb[0] - aa[aaa-1])\n\t\telse:\n\t\t\tbbbb = min(abs(bb[0] - aa[aaa-1])+min(abs(cc-aa[aaa-1]),abs(cc-bb[0])),abs(bb[0] - aa[aaa])+min(abs(cc-aa[aaa]),abs(cc-bb[0])))\n\t\t\tprint(bbbb)\n\telif aaa == a:\n\t\taaaa = min(abs(bb[bbb] - aa[a-1])+min(abs(cc-aa[a-1]),abs(cc-bb[bbb])),abs(bb[bbb-1] - aa[a-1])+min(abs(cc-aa[a-1]),abs(cc-bb[bbb-1])))\n\t\tprint(aaaa)\n\telif bbb == b:\n\t\tbbbb = min(abs(bb[b-1] - aa[aaa-1])+min(abs(cc-aa[aaa-1]),abs(cc-bb[b-1])),abs(bb[b-1] - aa[aaa])+min(abs(cc-aa[aaa]),abs(cc-bb[b-1])))\n\t\tprint(bbbb)\n\telse:\n\t\taaaa = min(max(aa[aaa],bb[bbb])-cc,cc-min(aa[aaa-1],bb[bbb-1]),2*aa[aaa] - cc - bb[bbb-1],aa[aaa] + cc - 2 * bb[bbb-1])\n\t\tprint(aaaa)', 'import bisect\na,b,c = map(int,input().split())\n\naa = []\nbb = []\nfor i in range(a):\n\taa.append(int(input()))\nfor i in range(b):\n\tbb.append(int(input()))\nfor i in range(c):\n\tcc = int(input())\n\taaa = bisect.bisect_left(aa,cc)\n\tbbb = bisect.bisect_left(bb,cc)\n\tif aaa == 0 and bbb == 0:\n\t\tprint(max(aa[0],bb[0]) - cc)\n\telif aaa == a and bbb == b:\n\t\tprint(cc - min(aa[a-1],bb[b-1]))\n\telif aaa == 0:\n\t\tif bbb == b:\n\t\t\tprint(min(abs(cc - aa[0]),abs(cc - bb[bbb-1])) + aa[0] - bb[bbb-1])\n\t\telse:\n\t\t\taaaa = min(abs(bb[bbb] - aa[0])+min(abs(cc-aa[0]),abs(cc-bb[bbb])),abs(bb[bbb-1] - aa[0])+min(abs(cc-aa[aaa]),abs(cc-bb[bbb-1])))\n\t\t\tprint(aaaa)\n\telif bbb == 0:\n\t\tif aaa == a:\n\t\t\tprint(min(abs(cc - aa[a-1]),abs(cc - bb[0])) + bb[0] - aa[aaa-1])\n\t\telse:\n\t\t\tbbbb = min(abs(bb[0] - aa[aaa-1])+min(abs(cc-aa[aaa-1]),abs(cc-bb[0])),abs(bb[0] - aa[aaa])+min(abs(cc-aa[aaa]),abs(cc-bb[0])))\n\t\t\tprint(bbbb)\n\telif aaa == a:\n\t\taaaa = min(abs(bb[bbb] - aa[a-1])+min(abs(cc-aa[a-1]),abs(cc-bb[bbb])),abs(bb[bbb-1] - aa[a-1])+min(abs(cc-aa[a-1]),abs(cc-bb[bbb-1])))\n\t\tprint(aaaa)\n\telif bbb == b:\n\t\tbbbb = min(abs(bb[b-1] - aa[aaa-1])+min(abs(cc-aa[aaa-1]),abs(cc-bb[b-1])),abs(bb[b-1] - aa[aaa])+min(abs(cc-aa[aaa]),abs(cc-bb[b-1])))\n\t\tprint(bbbb)\n\telse:\n\t\taaaa = min(max(aa[aaa],bb[bbb])-cc,cc-min(aa[aaa-1],bb[bbb-1]),2*aa[aaa] - cc - bb[bbb-1],aa[aaa] + cc - 2 * bb[bbb-1],2*bb[bbb] - cc - aa[aaa-1],bb[bbb] + cc - 2 * aa[aaa-1])\n\t\tprint(aaaa)\n']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s234959569', 's453430199', 's635472037']
[12148.0, 3064.0, 12140.0]
[1477.0, 17.0, 1529.0]
[1366, 1369, 1425]
p03112
u814663076
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
["import sys\nfrom sys import stdin\nimport numpy as np\n\ndef near(arr, num):\n\tindex = np.abs(arr - num).argmin()\n\treturn index\n\n'''\nA, B, Q = [int(i) for i in stdin.readline().split()]\ns = np.asarray([int(stdin.readline()) for _ in range(A)])\nt = np.asarray([int(stdin.readline()) for _ in range(B)])\nx = [int(stdin.readline()) for _ in range(Q)]\n\n'''\nA, B, Q =[2, 3, 4]\ns = [100,600]\nt=[400,900,1000]\nx=[150,2000,899,799]\n\nst = np.hstack((s, t))\nprint(st, file=sys.stderr)\nfor i in range(Q):\n\tindex = near(st, x[i])\n\tprint(index, file=sys.stderr)\n\tif index<A:\n\t\tprint(abs(x[i]-st[index]) + abs(st[index]-t[near(t, st[index])]))\n\telse:\n\t\tprint(abs(x[i]-st[index]) + abs(st[index]-s[near(s, st[index])]))\n\t\t", 'import sys\nfrom bisect import bisect_right\ninput = sys.stdin.readline().strip()\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nxs = [int(input()) for i in range(Q)]\nfor x in xs:\n b, d = bisect_right(s, x), bisect_right(t, x)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)', 'import sys\nfrom bisect import bisect_right\ninput = sys.stdin.readline\nA, B, Q = map(int, input().split())\nINF = 10 ** 18\ns = [-INF] + [int(input()) for i in range(A)] + [INF]\nt = [-INF] + [int(input()) for i in range(B)] + [INF]\nxs = [int(input()) for i in range(Q)]\nfor x in xs:\n b, d = bisect_right(s, x), bisect_right(t, x)\n res = INF\n for S in [s[b - 1], s[b]]:\n for T in [t[d - 1], t[d]]:\n d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)\n res = min(res, d1, d2)\n print(res)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s149113977', 's783829235', 's211342570']
[12404.0, 3064.0, 16256.0]
[149.0, 17.0, 868.0]
[702, 539, 529]
p03112
u815659544
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\n\n#%%\na,b,q = map(int, input().split())\nINF = 10**18\nshrines = [-INF] + [int(input() for _ in range(a))] + [INF]\ntemples = [-INF] + [int(input() for _ in range(b))] + [INF]\n\nfor _ in range(q):\n\n start = int(input())\n\n \n shrine_east = shrines[bisect.bisect_right(shrines, start)]\n \n temple_east = temples[bisect.bisect_right(temples, start)]\n\n \n shrine_west = shirines[bisect.bisect_right(shrines, start) - 1]\n \n temple_west = temples[bisect.bisect_right(temples, start) - 1]\n\n ans = INF\n\n for shrine in [shrine_east, shrine_west]:\n for temple in [temple_east,temple_west]:\n cur = min(abs(shrine-start), abs(temple-start)) + abs(shrine-temple)\n ans = min(ans,cur)\n\n print(ans)\n', '#%%\nimport bisect\n\n#%%\na,b,q = map(int, input().split())\nINF = 10**18\nshrines = [-INF] + [int(input() for _ in range(a))] + [INF]\ntemples = [-INF] + [int(input() for _ in range(b))] + [INF]\n\nfor _ in range(q):\n\n start = int(input())\n\n \n shrine_east = shrines[bisect.bisect_right(shrines, start)]\n \n temple_east = temples[bisect.bisect_right(temples, start)]\n\n \n shrine_west = shrines[bisect.bisect_right(shrines, start) - 1]\n \n temple_west = temples[bisect.bisect_right(temples, start) - 1]\n\n ans = INF\n\n for shrine in [shrine_east, shrine_west]:\n for temple in [temple_east,temple_west]:\n cur = min(abs(shrine-start), abs(temple-start)) + abs(shrine-temple)\n ans = min(ans,cur)\n\n print(ans)\n\n\n\n#%%\narr = [4,8,12,16,20]\n\n#%%\nbisect.bisect_left(arr,12)\n\n#%%\nbisect.bisect_right(arr,12)\n\n#%%\n', "#%%\nimport numpy as np\n#%%\n\ns,t,q = list(map(int, input().split()))\nshrines = []\ntemples = []\nquestions = []\nanswers = []\ndist = np.empty((s,t),dtype='int64')\n\nfor _ in range(s):\n shrines.append(int(input()))\nshrines = np.array(shrines)\n\nfor _ in range(t):\n temples.append(int(input()))\ntemples = np.array(temples)\n\nfor _ in range(q):\n questions.append(int(input()))\n\nfor i, shrine in enumerate(shrines):\n dist[i]= [abs(shrine - temple) for temple in temples]\n\n#%%\nprint(shrines,temples,dist)\n\n#%%\nfor start in questions:\n min_shrine_start = float('inf')\n min_temple_start = float('inf')\n\n for i, st_s in enumerate(shrines - start):\n abs_st_s = abs(st_s)\n\n if abs_st_s < min_shrine_start:\n abs_st_s += np.min(dist[i])\n\n if abs_st_s < min_shrine_start:\n min_shrine_start = abs_st_s\n\n for j, st_t in enumerate(temples - start):\n abs_st_t = abs(st_t)\n\n if abs_st_t < min_temple_start:\n abs_st_t += np.min(dist[:,j])\n\n if abs_st_t < min_temple_start:\n min_temple_start = abs_st_t\n \n answers.append(min(min_shrine_start,min_temple_start))\n\n\nfor ans in answers:\n print(ans)\n", '#%%\nimport bisect\n\n#%%\na,b,q = map(int, input().split())\nINF = 10**18\nshrines = [-INF] + [int(input()) for _ in range(a)] + [INF]\ntemples = [-INF] + [int(input()) for _ in range(b)] + [INF]\n\nfor _ in range(q):\n\n start = int(input())\n\n \n shrine_east = shrines[bisect.bisect_right(shrines, start)]\n \n temple_east = temples[bisect.bisect_right(temples, start)]\n\n \n shrine_west = shrines[bisect.bisect_right(shrines, start) - 1]\n \n temple_west = temples[bisect.bisect_right(temples, start) - 1]\n\n ans = INF\n\n for shrine in [shrine_east, shrine_west]:\n for temple in [temple_east,temple_west]:\n cur = min(abs(shrine-start), abs(temple-start)) + abs(shrine-temple)\n ans = min(ans,cur)\n\n print(ans)\n\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s387417911', 's432511563', 's783178758', 's189736999']
[3064.0, 3064.0, 21804.0, 12804.0]
[18.0, 18.0, 2109.0, 1834.0]
[1152, 1253, 1203, 1156]
p03112
u823458368
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import bisect\nimport math\n\na, b, q = map(int, input().split())\ns = [-math.inf]\nt = [-math.inf]\nx = []\nfor _ in range(a):\n s.append(int(input()))\nfor _ in range(b):\n t.append(int(input()))\nfor _ in range(q):\n x.append(int(input()))\ns.append(math.inf)\nt.append(math.inf)\n\nfor i in x:\n ws = abs(s[bisect.bisect(s, i) - 1] - i)\n ws += min(abs(t[bisect.bisect(t, s[bisect.bisect(s, i) - 1])-1] - s[bisect.bisect(s, i) - 1]), \\\n abs(t[bisect.bisect(t, s[bisect.bisect(s, i) - 1])] - s[bisect.bisect(s, i) - 1]))\n \n es = abs(s[bisect.bisect(s, i)] - i)\n es += min(abs(t[bisect.bisect(t, s[bisect.bisect(s, i)])-1] - s[bisect.bisect(s, i)]), \\\n abs(t[bisect.bisect(t, s[bisect.bisect(s, i) - 1])] - s[bisect.bisect(s, i)]))\n \n wt = abs(t[bisect.bisect(t, i) - 1] - i)\n wt += min(abs(s[bisect.bisect(s, t[bisect.bisect(t, i) - 1])-1] - t[bisect.bisect(t, i) - 1]), \\\n abs(s[bisect.bisect(s, t[bisect.bisect(t, i) - 1])] - t[bisect.bisect(t, i) - 1]))\n \n et = abs(t[bisect.bisect(t, i)] - i)\n et += min(abs(t[bisect.bisect(t, s[bisect.bisect(s, i) - 1])-1] - s[bisect.bisect(s, i) - 1]), \\\n abs(t[bisect.bisect(t, s[bisect.bisect(s, i) - 1])] - s[bisect.bisect(s, i) - 1]))\n \n print(min(ws, es, wt, et))', 'import bisect\nimport math\n\na, b, q = map(int, input().split())\ns = [-math.inf]\nt = [-math.inf]\nx = []\nfor _ in range(a):\n s.append(int(input()))\nfor _ in range(b):\n t.append(int(input()))\nfor _ in range(q):\n x.append(int(input()))\ns.append(math.inf)\nt.append(math.inf)\n\nfor i in x:\n ws = abs(s[bisect.bisect(s, i) - 1] - i)\n if ws != math.inf:\n ws += min(abs(t[bisect.bisect(t, s[bisect.bisect(s, i) - 1])-1] - s[bisect.bisect(s, i) - 1]), \\\n abs(t[bisect.bisect(t, s[bisect.bisect(s, i) - 1])] - s[bisect.bisect(s, i) - 1]))\n else:\n ws = math.inf\n \n es = abs(s[bisect.bisect(s, i)] - i)\n if es != math.inf:\n es += min(abs(t[bisect.bisect(t, s[bisect.bisect(s, i)]) -1] - s[bisect.bisect(s, i)]), \\\n abs(t[bisect.bisect(t, s[bisect.bisect(s, i)])] - s[bisect.bisect(s, i)]))\n else:\n es = math.inf\n \n wt = abs(t[bisect.bisect(t, i) - 1] - i)\n if wt != math.inf:\n wt += min(abs(s[bisect.bisect(s, t[bisect.bisect(t, i) - 1])-1] - t[bisect.bisect(t, i) - 1]), \\\n abs(s[bisect.bisect(s, t[bisect.bisect(t, i) - 1])] - t[bisect.bisect(t, i) - 1]))\n else:\n wt = math.inf\n \n et = abs(t[bisect.bisect(t, i)] - i)\n if et != math.inf:\n et += min(abs(s[bisect.bisect(s, t[bisect.bisect(t, i)])-1] - t[bisect.bisect(t, i)]), \\\n abs(s[bisect.bisect(s, t[bisect.bisect(t, i)])] - t[bisect.bisect(t, i)]))\n else:\n et = math.inf\n \n print(min(ws, es, wt, et))']
['Wrong Answer', 'Accepted']
['s944447728', 's070834129']
[20944.0, 20884.0]
[1808.0, 1835.0]
[1293, 1530]
p03112
u830683746
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import sys\nimport bisect\ninput = sys.stdin.readline\n\na,b,q = map(int, input().split())\ns = [-1 for i in range(a)]\nt = [-1 for i in range(b)]\n\nfor i in range(a):\n\tS = int(input())\n s[i] = S\n \nfor i in range(b):\n\tT = int(input())\n t[i] = T\n \ns.sort()\nt.sort()\n\nfor i in range(q):\n\tx = int(input())\n slidx = bisect.bisect_left(s, x)\n tlidx = bisect.bisect_left(t, x) \n\tsl = x - s[slidx]\n\ttl = x - t[tlidx]\n tr = 90000000000 - x\n sr = 90000000000 - x\n if slidx < a-1:\n sr = s[slidx+1] - x\n if slidx < b-1:\n tr = t[tlidx+1] - x\n dist = min( [max(sl,tl), max(sr,tr), min(sr, sl)*2 + min(tr,tl), min(tr,tl)*2 + min(sr,sl)] )\n print(dist)', 'import sys\nimport bisect\ninput = sys.stdin.readline\n\na,b,q = map(int, input().split())\ns = [-1 for i in range(a)]\nt = [-1 for i in range(b)]\n\nfor i in range(a):\n\tS = int(input())\n s[i] = S\n \nfor i in range(b):\n\tT = int(input())\n t[i] = T\n \ns.sort()\nt.sort()\n\nfor i in range(q):\n\tx = int(input())\n slidx = bisect.bisect_left(s, x)\n tlidx = bisect.bisect_left(t, x) \n\tsl = x - s[slidx]\n\ttl = x - t[tlidx]\n tr = 90000000000 - x\n sr = 90000000000 - x\n if slidx < a-1:\n sr = s[slidx+1] - x\n if slidx < b-1:\n tr = t[tlidx+1] - x\n dist = min( max(sl,tl), max(sr,tr), min(sr, sl)*2 + min(tr,tl), min(tr,tl)*2 + min(sr,sl))\n print(dist)', 'import sys\nimport bisect\ninput = sys.stdin.readline\n\na,b,q = map(int,input().split())\n\ns = [-1 for i in range(a)]\nt = [-1 for i in range(b)]\n\nfor i in range(a):\n\tS = int(input())\n\ts[i] = S\n \nfor i in range(b):\n\tT = int(input())\n\tt[i] = T\n \ns.sort()\nt.sort()\nfor i in range(q):\n\tx = int(input())\n\n\tslidx = bisect.bisect_left(s, x) -1\n\ttlidx = bisect.bisect_left(t, x) -1\n\tsl = -20000000000\n\ttl = -20000000000\n\tsr = 20000000000\n\ttr = 20000000000\n\tif slidx >= 0:\n\t\tsl = s[slidx]\n\tif tlidx >= 0:\n\t\ttl = t[tlidx]\n\n\tif slidx < a-1:\n\t\tsr = s[slidx+1]\n\tif tlidx < b-1:\n\t\ttr = t[tlidx+1]\n\tsl = x - sl\n\ttl = x - tl\n\tsr = sr - x\n\ttr = tr - x\n\t#print([sl,tl,sr,tr])\n\tdist = min( [max(sl,tl), max(sr,tr), min(sr, sl)*2 + min(tr,tl), min(tr,tl)*2 + min(sr,sl)])\n\tprint(dist)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s427877349', 's992648072', 's712477538']
[2940.0, 2940.0, 13712.0]
[17.0, 18.0, 727.0]
[676, 673, 766]
p03112
u839857256
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import sys\nfrom collections import deque\n\n\ndef bfs(s):\n flag_list[s] = 1\n color_list[s] = 0\n q.append(s)\n while len(q)>0:\n u = q.popleft()\n for v, w in enumerate(m_list[u]):\n if w > 0 and flag_list[v] == 0:\n flag_list[v] = 1\n if w%2 == 0:\n color_list[v] = color_list[u]\n else:\n color_list[v] = (color_list[u]+1)%2\n q.append(v)\n flag_list[u] = 2\n\n\nif __name__ == "__main__":\n input = sys.stdin.readline\n n = int(input())\n m_list = [[0]*n for _ in range(n)]\n color_list = [0]*n\n flag_list = [0]*n\n q = deque([])\n for _ in range(n-1):\n u, v, w = map(int, input().split())\n m_list[u-1][v-1] = w\n m_list[v-1][u-1] = w\n bfs(0)\n for color in color_list:\n print(color)\n', 'import sys\nimport bisect\n\n\ninput = sys.stdin.readline\na, b, q = map(int, input().split())\ninf = 10**12\ns_list = [-inf] + [int(input()) for _ in range(a)] + [inf]\ns_list.sort()\nt_list = [-inf] + [int(input()) for _ in range(b)] + [inf]\nt_list.sort()\nans_list =[]\nfor _ in range(q):\n x = int(input())\n s_idx = bisect.bisect_right(s_list, x)\n t_idx = bisect.bisect_right(t_list, x)\n ans = inf\n for s in [s_list[s_idx-1], s_list[s_idx]]:\n for t in [t_list[t_idx-1], t_list[t_idx]]:\n ans = min(ans, min(abs(x-s), abs(x-t)) + abs(s-t))\n print(ans)\n']
['Runtime Error', 'Accepted']
['s864022507', 's570418783']
[3316.0, 14484.0]
[21.0, 880.0]
[858, 578]
p03112
u844646164
2,000
1,048,576
Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i 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.)
['import numpy as np\nA, B, C = map(int, input().split())\ns = np.array([int(input()) for _ in range(A)])\nt = np.array([int(input()) for _ in range(B)])\nx = np.array([int(input()) for _ in range(C)])\nfor i in x:\n si = i-s\n asi = list(abs(si))\n min_si = min(asi)\n s_idx = asi.index(min_si)\n ti = i-t\n ati = list(abs(ti))\n min_ti = min(ati)\n t_idx = ati.index(min_ti)\n if si[s_idx] * ti[t_idx] < 0:\n if min_si <= min_ti:\n print(min_si*2+min_ti)\n else:\n print(min_ti*2+min_si)\n else:\n print(max(min_si, min_ti))\n', "import sys\nimport bisect\ninput = sys.stdin.readline\nA, B, Q = map(int, input().split())\ns = [int(input()) for _ in range(A)]\nt = [int(input()) for _ in range(B)]\ns = sorted(s)\nt = sorted(t)\n\nfor _ in range(Q):\n x = int(input())\n idx1 = bisect.bisect_right(s, x)\n idx2 = bisect.bisect_right(t, x)\n ans = float('inf')\n if idx1 > 0:\n left_s = s[idx1-1]\n else:\n left_s = float('inf')\n if idx2 > 0:\n left_t = t[idx2-1]\n else:\n left_t = float('inf')\n if idx1 < A:\n right_s = s[idx1]\n else:\n right_s = float('inf')\n if idx2 < B:\n right_t = t[idx2]\n else:\n right_t = float('inf')\n\n ls = x-left_s\n lt = x-left_t\n rs = right_s-x\n rt = right_t-x \n if left_s <= x <= right_t:\n tmp = right_t-left_s + min(ls, rt)\n ans = min(ans, tmp)\n if left_t <= x <= right_s:\n tmp = right_s-left_t + min(lt, rs)\n ans = min(ans, tmp)\n ans = min(ans, max(abs(ls), abs(lt)))\n ans = min(ans, max(abs(rs), abs(rt)))\n print(ans)\n"]
['Wrong Answer', 'Accepted']
['s211601765', 's573483175']
[29076.0, 12196.0]
[2109.0, 776.0]
[578, 1043]