Buggy python submission (verdict: Runtime Error):
import bisect
A, B, Q = map(int, input().split())
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
t = [-INF] + [int(input()) for _ in range(B)] + [INF]
for i in range(Q):
  x = int(input())
  sw = bisect.bisect_right(s, x)-1 #xより西で一番近い(同じ場所でもいい)神社の番号
  se = sw + 1 #xより東で一番近い神社の番号
  tw = bisect.bisect_right(t, x)-1
  te = tw + 1
  res = INF
  for S in [sw, se]:
    for T in [tw, te]:
      d1, d2 = abs(x-S) + abs(T-S), abs(x-T) + abs(S-T)
      res = min(res, d1, d2)
  print(res)



Fixed submission:
import bisect
INF = 10**15
A, B, Q = map(int, input().split())
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
t = [-INF] + [int(input()) for _ in range(B)] + [INF]
for i in range(Q):
  x = int(input())
  sw = bisect.bisect_right(s, x)-1 #xより西で一番近い(同じ場所でもいい)神社の番号
  se = sw + 1 #xより東で一番近い神社の番号
  tw = bisect.bisect_right(t, x)-1
  te = tw + 1
  res = INF
  for S in [s[sw], s[se]]:
    for T in [t[tw], t[te]]:
      d1, d2 = abs(x-S) + abs(T-S), abs(x-T) + abs(S-T)
      res = min(res, d1, d2)
  print(res)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  import bisect
  A, B, Q = map(int, input().split())
  s = list()
  t = list()
  s.append(-10**12)
  t.append(-10**12)
  for i in range(A):
    s.append(int(input()))
  for i in range(B):
    t.append(int(input()))
  s.append(10**12)
  t.append(10**12)
  for i in range(Q):
    x = int(input())
    sw = bisect.bisect_right(s, x)-1 #xより西で一番近い(同じ場所でもいい)神社の番号
    se = sw + 1 #xより東で一番近い神社の番号
    tw = bisect.bisect_right(t, x)-1
    te = tw + 1
    l1 = max(x-s[sw], x-t[tw])
    l2 = max(s[se]-x, t[te]-x)
    l3 = s[se]-x + s[se]-t[tw]
    l4 = t[te]-x + t[te]-s[sw]
    l5 = x-s[sw] + t[te]-s[sw]
    l6 = x-t[tw] + s[se]-t[tw]
    print(min(l1, l2, l3, l4, l5, l6))
main()

Fixed submission:
import bisect
INF = 10**15
A, B, Q = map(int, input().split())
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
t = [-INF] + [int(input()) for _ in range(B)] + [INF]
for i in range(Q):
  x = int(input())
  sw = bisect.bisect_right(s, x)-1 #xより西で一番近い(同じ場所でもいい)神社の番号
  se = sw + 1 #xより東で一番近い神社の番号
  tw = bisect.bisect_right(t, x)-1
  te = tw + 1
  res = INF
  for S in [s[sw], s[se]]:
    for T in [t[tw], t[te]]:
      d1, d2 = abs(x-S) + abs(T-S), abs(x-T) + abs(S-T)
      res = min(res, d1, d2)
  print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
A, B, Q = map(int, input().split())
s = list()
t = list()
s.append(-10**12)
t.append(-10**12)
for i in range(A):
  s.append(int(input()))
for i in range(B):
  t.append(int(input()))
s.append(10**12)
t.append(10**12)
for i in range(Q):
  x = int(input())
  sw = bisect.bisect_right(s, x)-1 #xより西で一番近い(同じ場所でもいい)神社の番号
  se = sw + 1 #xより東で一番近い神社の番号
  tw = bisect.bisect_right(t, x)-1
  te = tw + 1
  l1 = max(x-s[sw], x-t[tw])
  l2 = max(s[se]-x, t[te]-x)
  l3 = s[se]-x + s[se]-t[tw]
  l4 = t[te]-x + t[te]-s[sw]
  l5 = x-s[sw] + t[te]-s[sw]
  l6 = x-t[tw] + s[se]-t[tw]
  print(min(l1, l2, l3, l4, l5, l6))

Fixed submission:
import bisect
INF = 10**15
A, B, Q = map(int, input().split())
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
t = [-INF] + [int(input()) for _ in range(B)] + [INF]
for i in range(Q):
  x = int(input())
  sw = bisect.bisect_right(s, x)-1 #xより西で一番近い(同じ場所でもいい)神社の番号
  se = sw + 1 #xより東で一番近い神社の番号
  tw = bisect.bisect_right(t, x)-1
  te = tw + 1
  res = INF
  for S in [s[sw], s[se]]:
    for T in [t[tw], t[te]]:
      d1, d2 = abs(x-S) + abs(T-S), abs(x-T) + abs(S-T)
      res = min(res, d1, d2)
  print(res)