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

A, B, Q = map(int, input().split())
s = []
for i in range(A):
    s.append(int(input()))
t = []
for i in range(B):
    t.append(int(input()))
x = []
for i in range(Q):
    x.append(int(input()))

for i in range(Q):
    sx, tx, sy, ty = [], [], [], []
    for j in s:
        sx.append(abs(j - x[i]))
    for j in t:
        tx.append(abs(j - x[i]))
    sxi = sx.index(min(sx))
    txi = tx.index(min(tx))
    for j in t:
        ty.append(abs(j - s[sxi]))
    for j in s:
        sy.append(abs(j - t[txi]))
    a = min(sx) + min(ty)
    b = min(tx) + min(sy)
    if a < b:
        print(str(a))
    else:
        print(str(b))


Fixed submission:
import bisect

A, B, Q = map(int, input().split())
INF = 10**18
S = [-INF]
for i in range(A):
    S.append(int(input()))
S.append(INF)
T = [-INF]
for i in range(B):
    T.append(int(input()))
T.append(INF)
X = []
for i in range(Q):
    X.append(int(input()))

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

Buggy python submission (verdict: Time Limit Exceeded):
A, B, Q = map(int, input().split())
s = []
for i in range(A):
    s.append(int(input()))
s.sort()
t = []
t.sort()
for i in range(B):
    t.append(int(input()))
x = []
for i in range(Q):
    x.append(int(input()))

for i in range(Q):
    sx, tx, sy, ty = [], [], [], []
    for j in s:
        sx.append(abs(j - x[i]))
    for j in t:
        tx.append(abs(j - x[i]))
    sxi = sx.index(min(sx))
    txi = tx.index(min(tx))
    for j in t:
        ty.append(abs(j - s[sxi]))
    for j in s:
        sy.append(abs(j - t[txi]))
    a = min(sx) + min(ty)
    b = min(tx) + min(sy)
    if a < b:
        print(str(a))
    else:
        print(str(b))


Fixed submission:
import bisect

A, B, Q = map(int, input().split())
INF = 10**18
S = [-INF]
for i in range(A):
    S.append(int(input()))
S.append(INF)
T = [-INF]
for i in range(B):
    T.append(int(input()))
T.append(INF)
X = []
for i in range(Q):
    X.append(int(input()))

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

Buggy python submission (verdict: Time Limit Exceeded):
A, B, Q = map(int, input().split())
s = []
for i in range(A):
    s.append(int(input()))
s.sort()
t = []
t.sort()
for i in range(B):
    t.append(int(input()))
x = []
for i in range(Q):
    x.append(int(input()))

for i in range(Q):
    sx, tx, sy, ty = [], [], [], []
    for j in range(A):
        sx.append(abs(s[j] - x[i]))
    for j in range(B):
        tx.append(abs(t[j] - x[i]))
    sxi = sx.index(min(sx))
    txi = tx.index(min(tx))
    for j in range(B):
        ty.append(abs(t[j] - s[sxi]))
    for j in range(A):
        sy.append(abs(s[j] - t[txi]))
    a = min(sx) + min(ty)
    b = min(tx) + min(sy)
    if a < b:
        print(str(a))
    else:
        print(str(b))


Fixed submission:
import bisect

A, B, Q = map(int, input().split())
INF = 10**18
S = [-INF]
for i in range(A):
    S.append(int(input()))
S.append(INF)
T = [-INF]
for i in range(B):
    T.append(int(input()))
T.append(INF)
X = []
for i in range(Q):
    X.append(int(input()))

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

Buggy python submission (verdict: Runtime Error):
A, B, Q = map(int, input().split())
s = []
for i in range(A):
    s.append(int(input()))
s.sort()
t = []
t.sort()
for i in range(B):
    t.append(int(input()))
x = []
for i in range(Q):
    x.append(int(input()))

for i in range(Q):
    sx, tx, sy, ty = [], [], [], []
    for j in range(A):
        sx.append(abs(s[j] - x[i]))
    for j in range(B):
        tx.append(abs(t[j] - x[i]))
    sxi = sx.index(min(sx))
    txi = tx.index(min(tx))
    for j in range(B):
        ty.append(abs(t[j] - s[sxi]))
    for j in range(A):
        sy.append(abs(s[j] - t[sxi]))
    a = min(sx) + min(ty)
    b = min(tx) + min(sy)
    if a < b:
        print(a)
    else:
        print(b)


Fixed submission:
import bisect

A, B, Q = map(int, input().split())
INF = 10**18
S = [-INF]
for i in range(A):
    S.append(int(input()))
S.append(INF)
T = [-INF]
for i in range(B):
    T.append(int(input()))
T.append(INF)
X = []
for i in range(Q):
    X.append(int(input()))

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

Buggy python submission (verdict: Runtime Error):
A, B, Q = map(int, input().split())
s = []
for i in range(A):
    s.append(int(input()))
s.sort()
t = []
t.sort()
for i in range(B):
    t.append(int(input()))
x = []
for i in range(Q):
    x.append(int(input()))

for i in range(Q):
    sx, tx, sy, ty = [], [], [], []
    for j in range(A):
        sx.append(abs(s[j] - x[i]))
    for j in range(B):
        tx.append(abs(t[j] - x[i]))
    sxi = sx.index(min(sx))
    txi = tx.index(min(tx))
    for j in range(B):
        ty.append(abs(t[j] - s[sxi]))
    for j in range(A):
        sy.append(abs(s[j] - t[sxi]))
    a = min(sx) + min(ty)
    b = min(tx) + min(sy)
    if a < b:
        print("a"+str(a))
    else:
        print("b"+str(b))


Fixed submission:
import bisect

A, B, Q = map(int, input().split())
INF = 10**18
S = [-INF]
for i in range(A):
    S.append(int(input()))
S.append(INF)
T = [-INF]
for i in range(B):
    T.append(int(input()))
T.append(INF)
X = []
for i in range(Q):
    X.append(int(input()))

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