Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import numpy as np
INF = 10 ** 12

A, B, Q = list(map(int, input().split()))
S, T, X = [-INF], [-INF], []
for _ in range(A):
    S.append(int(input()))
for _ in range(B):
    T.append(int(input()))
for _ in range(Q):
    X.append(int(input()))
S.append(INF)
T.append(INF)
S = np.array(S)
T = np.array(T)

for x in X:
    ans = INF
    sr = np.searchsorted(S, x)
    tr = np.searchsorted(T, x)
    for s in S[sr-1: sr+1]:
        for t in T[tr-1: tr+1]:
            ans = min(ans, abs(s-x) + abs(s-t), abs(t-x) + abs(s-t))
    print(ans)


Fixed submission:
import bisect
A, B, Q = list(map(int, input().split()))
S, T, X = [], [], []
for _ in range(A):
    S.append(int(input()))
for _ in range(B):
    T.append(int(input()))
for _ in range(Q):
    X.append(int(input()))
INF = 10 ** 12
S = [-INF] + S + [INF]
T = [-INF] + T + [INF]

for x in X:
    ans = INF
    sr = bisect.bisect_right(S, x)
    tr = bisect.bisect_right(T, x)
    for s in S[sr-1: sr+1]:
        for t in T[tr-1: tr+1]:
            ans = min(ans, abs(s-x) + abs(s-t), abs(t-x) + abs(s-t))
    print(ans)

Buggy python submission (verdict: Runtime Error):
import bisect
A, B, Q = list(map(int, input().split()))
S, T, X = [-INF], [-INF], []
for _ in range(A):
    S.append(int(input()))
for _ in range(B):
    T.append(int(input()))
for _ in range(Q):
    X.append(int(input()))
INF = 10 ** 12
S.append(INF)
T.append(INF)

for x in X:
    ans = INF
    sr = bisect.bisect_right(S, x)
    tr = bisect.bisect_right(T, x)
    for s in S[sr-1: sr+1]:
        for t in T[tr-1: tr+1]:
            ans = min(ans, abs(s-x) + abs(s-t), abs(t-x) + abs(s-t))
    print(ans)


Fixed submission:
import bisect
A, B, Q = list(map(int, input().split()))
S, T, X = [], [], []
for _ in range(A):
    S.append(int(input()))
for _ in range(B):
    T.append(int(input()))
for _ in range(Q):
    X.append(int(input()))
INF = 10 ** 12
S = [-INF] + S + [INF]
T = [-INF] + T + [INF]

for x in X:
    ans = INF
    sr = bisect.bisect_right(S, x)
    tr = bisect.bisect_right(T, x)
    for s in S[sr-1: sr+1]:
        for t in T[tr-1: tr+1]:
            ans = min(ans, abs(s-x) + abs(s-t), abs(t-x) + abs(s-t))
    print(ans)

Buggy python submission (verdict: Runtime Error):
a, b, q = list(map(int, input().split()))
ss, tt, xx = [], [], []
for _ in range(a):
    ss.append(int(input()))
for _ in range(b):
    tt.append(int(input()))
for _ in range(q):
    xx.append(int(input()))

ss.sort()
tt.sort()

import bisect
def get_left(aa, bb, pos):
    a1 = bisect.bisect_left(aa, pos)
    b1 = bisect.bisect_left(bb, pos)
    if a1 == b1 == 0:
        return 10 ** 9
    if a1 == 0 or (b1 > 0 and bb[b1 - 1] > aa[a1 - 1]):
        dists = [10 ** 9]
        if a1 < len(aa):
            dists.append(pos - bb[b1 - 1] + aa[a1] - bb[b1 - 1])
        if a1 > 0:
            dists.append(pos - aa[a1 - 1])
        return min(dists)
    dists = [10 ** 9]
    if b1 < len(bb):
        dists.append(pos - aa[a1 - 1] + bb[b1] - aa[a1 - 1])
    if b1 > 0:
        dists.append(pos - bb[b1 - 1])
    return min(dists)

def get_right(aa, bb, pos):
    a1 = bisect.bisect_left(aa, pos)
    b1 = bisect.bisect_left(bb, pos)
    if a1 == len(aa) and b1 == len(bb):
        return 10 ** 9
    if a1 == len(aa) or (b1 < len(bb) and bb[b1] < aa[a1]):
        dists = [10 ** 9]
        if a1 > 0:
            dists.append(- pos + bb[b1] - aa[a1 - 1] + bb[b1])
        if a1 < len(aa):
            dists.append(aa[a1] - pos)
        return min(dists)
    dists = [10 ** 9]
    if b1 > 0:
        dists.append(- pos + aa[a1] - bb[b1 - 1] + aa[a1])
    if b1 > 0:
        dists.append(bb[b1] - pos)
    return min(dists)

for x in xx:
    print(min(get_left(ss, tt, x), get_right(ss, tt, x)))


Fixed submission:
import bisect
A, B, Q = list(map(int, input().split()))
S, T, X = [], [], []
for _ in range(A):
    S.append(int(input()))
for _ in range(B):
    T.append(int(input()))
for _ in range(Q):
    X.append(int(input()))
INF = 10 ** 12
S = [-INF] + S + [INF]
T = [-INF] + T + [INF]

for x in X:
    ans = INF
    sr = bisect.bisect_right(S, x)
    tr = bisect.bisect_right(T, x)
    for s in S[sr-1: sr+1]:
        for t in T[tr-1: tr+1]:
            ans = min(ans, abs(s-x) + abs(s-t), abs(t-x) + abs(s-t))
    print(ans)