Buggy python submission (verdict: Time Limit Exceeded):
import bisect
from functools import reduce

A, B, Q = map(int,input().split())
INF = float("inf")
s = [-1*INF]
t = [-1*INF]
for _ in range(A):
    s.append(int(input()))
s.append(INF)
for _ in range(B):
    t.append(int(input()))
t.append(INF)
for _ in range(Q):
    x = int(input())
    s_index = bisect.bisect_left(s,x)
    t_index = bisect.bisect_left(t,x)
    s_l = x - s[s_index-1]
    s_r = s[s_index] - x
    t_l = x - t[t_index-1]
    t_r = t[t_index] - x
    ans = reduce(min, [max(s_l,t_l), s_l + t_r*2, s_r + t_l*2, s_l*2 + t_r, s_r*2 + t_l, max(s_r,t_r)])
    print(ans)

Fixed submission:
from bisect import bisect_left
A, B, Q = map(int,input().split())
INF = 2 * 10 ** 10
S = [-INF]
T = [-INF]
for _ in range(A):
    S.append(int(input()))
S.append(INF)
for _ in range(B):
    T.append(int(input()))
T.append(INF)
for _ in range(Q):
    x = int(input())
    s = bisect_left(S, x)
    t = bisect_left(T, x)
    ans = min(max(S[s], T[t]) - x, x - min(S[s-1], T[t-1]), 2 * S[s] - T[t-1] - x, 2 * T[t] - S[s-1] - x, T[t] + x - 2 * S[s-1], S[s] + x - 2 * T[t-1])
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

A, B, Q = map(int,input().split())
INF = float("inf")
s = [-1*INF]
t = [-1*INF]
for _ in range(A):
    s.append(int(input()))
s.append(INF)
for _ in range(B):
    t.append(int(input()))
t.append(INF)
for _ in range(Q):
    x = int(input())
    s_index = bisect.bisect_left(s,x)
    t_index = bisect.bisect_left(t,x)
    s_l = x - s[s_index-1]
    s_r = s[s_index] - x
    t_l = x - t[t_index-1]
    t_r = t[t_index] - x
    print(min(max(s_l,t_l), s_l + t_r*2, s_r + t_l*2, s_l*2 + t_r, s_r*2 + t_l, max(s_r,t_r)))

Fixed submission:
from bisect import bisect_left
A, B, Q = map(int,input().split())
INF = 2 * 10 ** 10
S = [-INF]
T = [-INF]
for _ in range(A):
    S.append(int(input()))
S.append(INF)
for _ in range(B):
    T.append(int(input()))
T.append(INF)
for _ in range(Q):
    x = int(input())
    s = bisect_left(S, x)
    t = bisect_left(T, x)
    ans = min(max(S[s], T[t]) - x, x - min(S[s-1], T[t-1]), 2 * S[s] - T[t-1] - x, 2 * T[t] - S[s-1] - x, T[t] + x - 2 * S[s-1], S[s] + x - 2 * T[t-1])
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

A, B, Q = map(int,input().split())
INF = 30000000000
s = [-1*INF]
t = [-1*INF]
for _ in range(A):
    s.append(int(input()))
s.append(INF)
for _ in range(B):
    t.append(int(input()))
t.append(INF)
for _ in range(Q):
    x = int(input())
    s_index = bisect.bisect_left(s,x)
    t_index = bisect.bisect_left(t,x)
    s_l = x - s[s_index-1]
    s_r = s[s_index] - x
    t_l = x - t[t_index-1]
    t_r = t[t_index] - x
    print(min(max(s_l,t_l), s_l + t_r*2, s_r + t_l*2, s_l*2 + t_r, s_r*2 + t_l, max(s_r,t_r)))

Fixed submission:
from bisect import bisect_left
A, B, Q = map(int,input().split())
INF = 2 * 10 ** 10
S = [-INF]
T = [-INF]
for _ in range(A):
    S.append(int(input()))
S.append(INF)
for _ in range(B):
    T.append(int(input()))
T.append(INF)
for _ in range(Q):
    x = int(input())
    s = bisect_left(S, x)
    t = bisect_left(T, x)
    ans = min(max(S[s], T[t]) - x, x - min(S[s-1], T[t-1]), 2 * S[s] - T[t-1] - x, 2 * T[t] - S[s-1] - x, T[t] + x - 2 * S[s-1], S[s] + x - 2 * T[t-1])
    print(ans)