Buggy python submission (verdict: Time Limit Exceeded):
A,B,Q = list(map(int,input().split())) 
S = [int(input()) for _ in range(A) ]
T = [int(input()) for _ in range(B) ]
x = [int(input()) for _ in range(Q)]
#S = np.array(S)
#T = np.array(T)
for a in x:
    ans1 = 0
    ans2 = 0
    S1 = list(map(lambda x : abs(x-a),S))
    T1 = list(map(lambda x: abs(x-a),T))
    ans1 +=min(T1)
    ans1 += min(map(lambda x:abs(x-T[T1.index(min(T1))]),S))
    ans2+=min(S1)
    ans2+= min(map(lambda x:abs(x-S[S1.index(min(S1))]),T))
    print(min(ans1,ans2))

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

for a in x:
    ans1 = 0
    ans2 = 0
    b = bisect.bisect_left(S,a)
    c = bisect.bisect_left(T,a)
    res = INF
    for s in [S[b-1],S[b]]:
        for t in [T[c-1],T[c]]:
            d1,d2 = abs(s-a)+abs(s-t),abs(t-a)+abs(s-t)
            res = min(res,d1,d2)
    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
A,B,Q = list(map(int,input().split())) 
S = [int(input()) for _ in range(A) ]
T = [int(input()) for _ in range(B) ]
x = [int(input()) for _ in range(Q)]
#S = np.array(S)
#T = np.array(T)
for a in x:
    ans1 = 0
    ans2 = 0
    S1 = list(map(lambda x : abs(x-a),S))
    T1 = list(map(lambda x: abs(x-a),T))
    ans1 +=min(T1)
    ans1 += min(map(lambda x:abs(x-T[T1.index(min(T1))]),S))
    ans2+=min(S1)
    ans2+= min(map(lambda x:abs(x-S[S1.index(min(S1))]),T))
    print(min(ans1,ans2))

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

for a in x:
    ans1 = 0
    ans2 = 0
    b = bisect.bisect_left(S,a)
    c = bisect.bisect_left(T,a)
    res = INF
    for s in [S[b-1],S[b]]:
        for t in [T[c-1],T[c]]:
            d1,d2 = abs(s-a)+abs(s-t),abs(t-a)+abs(s-t)
            res = min(res,d1,d2)
    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
A,B,Q = list(map(int,input().split())) 
S = [int(input()) for _ in range(A) ]
T = [int(input()) for _ in range(B) ]
x = [int(input()) for _ in range(Q)]
S = np.array(S)
T = np.array(T)
for a in x:
    ans1 = 0
    ans2 = 0
    S1 = abs(S-a)
    T1 = abs(T-a)
    ans1 +=np.min(T1)
    ans1 += np.min(abs(S-T[np.argmin(T1)]))
    ans2+=np.min(S1)
    ans2+= np.min(abs(T-S[np.argmin(S1)]))
    print(min(ans1,ans2))

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

for a in x:
    ans1 = 0
    ans2 = 0
    b = bisect.bisect_left(S,a)
    c = bisect.bisect_left(T,a)
    res = INF
    for s in [S[b-1],S[b]]:
        for t in [T[c-1],T[c]]:
            d1,d2 = abs(s-a)+abs(s-t),abs(t-a)+abs(s-t)
            res = min(res,d1,d2)
    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
A,B,Q = list(map(int,input().split())) 
S = [int(input()) for _ in range(A) ]
T = [int(input()) for _ in range(B) ]
x = [int(input()) for _ in range(Q)]
S = np.array(S)
T = np.array(T)
for a in x:
    ans1 = 0
    ans2 = 0
    S1 = abs(S-a)
    T1 = abs(T-a)
    ans1 +=np.min(T1)
    ans1 += min(abs(S-T[np.argmin(T1)]))
    ans2+=np.min(S1)
    ans2+= min(abs(T-S[np.argmin(S1)]))
    print(min(ans1,ans2))

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

for a in x:
    ans1 = 0
    ans2 = 0
    b = bisect.bisect_left(S,a)
    c = bisect.bisect_left(T,a)
    res = INF
    for s in [S[b-1],S[b]]:
        for t in [T[c-1],T[c]]:
            d1,d2 = abs(s-a)+abs(s-t),abs(t-a)+abs(s-t)
            res = min(res,d1,d2)
    print(res)