Buggy python submission (verdict: Time Limit Exceeded):
import bisect
A,B,Q = map(int,input().split())
S = [-float('inf')]+list(int(input())for i in range(A))+[float('inf')]
T = [-float('inf')]+list(int(input())for i in range(B))+[float('inf')]
x = list(int(input())for i in range(Q))

for i in x:
    si = bisect.bisect_left(S,i)
    ti = bisect.bisect_left(T,i)
    ans = min(max(S[si],T[ti])-i,i-min(S[si-1],T[ti-1]),\
            2*S[si]-i-T[ti-1],2*T[ti]-i-S[si-1],\
             T[ti]+i-2*S[si-1],S[si]+i-2*T[ti-1])
    print(ans)

Fixed submission:
import bisect
A,B,Q = map(int,input().split())
S = [-float('inf')]+list(int(input())for i in range(A))+[float('inf')]
T = [-float('inf')]+list(int(input())for i in range(B))+[float('inf')]
x = list(int(input())for i in range(Q))

for i in x:
    si = bisect.bisect_left(S,i)
    ti = bisect.bisect_left(T,i)
    ans = min(max(S[si],T[ti])-i,i-min(S[si-1],T[ti-1]),\
            2*S[si]-i-T[ti-1],2*T[ti]-i-S[si-1],\
             T[ti]+i-2*S[si-1],S[si]+i-2*T[ti-1])
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
A,B,Q = map(int,input().split())
S = [-float('inf')]+list(int(input())for i in range(A))+[float('inf')]
T = [-float('inf')]+list(int(input())for i in range(B))+[float('inf')]
x = list(int(input())for i in range(Q))

for i in x:
    si = bisect.bisect_left(S,i)
    ti = bisect.bisect_left(T,i)
    ans = min(max(S[si],T[ti])-i,i-min(S[si-1],T[ti-1]),\
            2*S[si]-i-T[ti-1],2*T[ti]-i-S[si-1],\
             T[ti]+i-2*S[si-1],S[si]+i-2*T[ti-1])
    print(ans)

Fixed submission:
import bisect
A,B,Q = map(int,input().split())
S = [-float('inf')]+list(int(input())for i in range(A))+[float('inf')]
T = [-float('inf')]+list(int(input())for i in range(B))+[float('inf')]
x = list(int(input())for i in range(Q))

for i in x:
    si = bisect.bisect_left(S,i)
    ti = bisect.bisect_left(T,i)
    ans = min(max(S[si],T[ti])-i,i-min(S[si-1],T[ti-1]),\
            2*S[si]-i-T[ti-1],2*T[ti]-i-S[si-1],\
             T[ti]+i-2*S[si-1],S[si]+i-2*T[ti-1])
    print(ans)

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

def len_L(s,x):
    L= 99999999999
    for i in s:
        if i <= x:
            L = x - i
        else:
            break
    return L

def len_R(s,x):
    for i in s:
        if i >= x:
            return i - x
    return 99999999999

for i in x:
    ls = len_L(s,i)
    lt = len_L(t,i)
    rs = len_R(s,i)
    rt = len_R(t,i)

    mini = min([2*ls+rt , ls+2*rt ,2*rs+lt , rs+2*lt , max([lt,ls]) , max([rt,rs])])
    print(mini)


Fixed submission:
import bisect
A,B,Q = map(int,input().split())
S = [-float('inf')]+list(int(input())for i in range(A))+[float('inf')]
T = [-float('inf')]+list(int(input())for i in range(B))+[float('inf')]
x = list(int(input())for i in range(Q))

for i in x:
    si = bisect.bisect_left(S,i)
    ti = bisect.bisect_left(T,i)
    ans = min(max(S[si],T[ti])-i,i-min(S[si-1],T[ti-1]),\
            2*S[si]-i-T[ti-1],2*T[ti]-i-S[si-1],\
             T[ti]+i-2*S[si-1],S[si]+i-2*T[ti-1])
    print(ans)

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

def len_L(s,x):
    L= 99999999999
    for i in s:
        if i <= x:
            L = x - i
        else:
            break
    return L

def len_R(s,x):
    for i in s:
        if i >= x:
            return i - x
    return 99999999999

for i in x:
    ls = len_L(s,i)
    lt = len_L(t,i)
    rs = len_R(s,i)
    rt = len_R(t,i)

    mini = min([2*ls+rt , ls+2*rt ,2*rs+lt , rs+2*lt , max([lt,ls]) , max([rt,rs])])
    print(mini)


Fixed submission:
import bisect
A,B,Q = map(int,input().split())
S = [-float('inf')]+list(int(input())for i in range(A))+[float('inf')]
T = [-float('inf')]+list(int(input())for i in range(B))+[float('inf')]
x = list(int(input())for i in range(Q))

for i in x:
    si = bisect.bisect_left(S,i)
    ti = bisect.bisect_left(T,i)
    ans = min(max(S[si],T[ti])-i,i-min(S[si-1],T[ti-1]),\
            2*S[si]-i-T[ti-1],2*T[ti]-i-S[si-1],\
             T[ti]+i-2*S[si-1],S[si]+i-2*T[ti-1])
    print(ans)

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

def len_L(s,x):
    L= 99999999999
    for i in s:
        if i <= x:
            L = x - i
    return L

def len_R(s,x):
    for i in s:
        if i >= x:
            return i - x
    return 99999999999

for i in x:
    mini = min([2*len_L(s,i)+len_R(t,i) , len_L(s,i)+2*len_R(t,i) ,2*len_R(s,i)+len_L(t,i) , len_R(s,i)+2*len_L(t,i) , max([len_L(t,i),len_L(s,i)]) , max([len_R(t,i),len_R(s,i)])])
    print(mini)


Fixed submission:
import bisect
A,B,Q = map(int,input().split())
S = [-float('inf')]+list(int(input())for i in range(A))+[float('inf')]
T = [-float('inf')]+list(int(input())for i in range(B))+[float('inf')]
x = list(int(input())for i in range(Q))

for i in x:
    si = bisect.bisect_left(S,i)
    ti = bisect.bisect_left(T,i)
    ans = min(max(S[si],T[ti])-i,i-min(S[si-1],T[ti-1]),\
            2*S[si]-i-T[ti-1],2*T[ti]-i-S[si-1],\
             T[ti]+i-2*S[si-1],S[si]+i-2*T[ti-1])
    print(ans)