Buggy python submission (verdict: Time Limit Exceeded):
A,B,Q=map(int,input().split())
inf=1e50
s=[int(input()) for _ in range(A)]
s=[-inf]+s+[inf]
t=[int(input()) for _ in range(B)]
t=[-inf]+t+[inf]

from bisect import bisect

for _ in range(Q):
    x=int(input())
    i=bisect(s,x)
    j=bisect(t,x)
    
    sL=x-s[i-1]
    sR=s[i]-x
    
    tL=x-t[j-1]
    tR=t[j]-x
    print(min(max(sR,tR),max(sL,tL),sR+tL+min(sR,tL),sL+tR+min(sL,tR)))




Fixed submission:
A,B,Q=map(int,input().split())
inf=1e50
s=[-inf]
for _ in range(A):
    s.append(int(input()))
s.append(inf)

t=[-inf]
for _ in range(B):
    t.append(int(input()))
t.append(inf)
from bisect import bisect

for _ in range(Q):
    x=int(input())
    i=bisect(s,x)
    j=bisect(t,x)
    
    sL=x-s[i-1]
    sR=s[i]-x
    
    tL=x-t[j-1]
    tR=t[j]-x
    print(min(max(sR,tR),max(sL,tL),sR+tL+min(sR,tL),sL+tR+min(sL,tR)))

Buggy python submission (verdict: Time Limit Exceeded):
A,B,Q=map(int,input().split())
inf=1e50
s=[-inf]
for _ in range(A):
    s.append(int(input()))
s.append(inf)

t=[-inf]
for _ in range(B):
    t.append(int(input()))
t.append(inf)
from bisect import bisect

for _ in range(Q):
    x=int(input())
    i=bisect(s,x)
    j=bisect(t,x)
    
    sL=x-s[i-1]
    sR=s[i]-x
    
    tL=x-t[j-1]
    tR=t[j]-x
    print(min(max(sR,tR),max(sL,tL),sR+tL+min(sR,tL),sL+tR+min(sL,tR)))




Fixed submission:
A,B,Q=map(int,input().split())
inf=1e50
s=[-inf]
for _ in range(A):
    s.append(int(input()))
s.append(inf)

t=[-inf]
for _ in range(B):
    t.append(int(input()))
t.append(inf)
from bisect import bisect

for _ in range(Q):
    x=int(input())
    i=bisect(s,x)
    j=bisect(t,x)
    
    sL=x-s[i-1]
    sR=s[i]-x
    
    tL=x-t[j-1]
    tR=t[j]-x
    print(min(max(sR,tR),max(sL,tL),sR+tL+min(sR,tL),sL+tR+min(sL,tR)))

Buggy python submission (verdict: Time Limit Exceeded):
A,B,Q=map(int,input().split())
s=[]
for _ in range(A):
    s.append(int(input()))
t=[]
for _ in range(B):
    t.append(int(input()))
from bisect import bisect
infty=1e50
for _ in range(Q):
    x=int(input())
    i=bisect(s,x)
    j=bisect(t,x)
    if 0<i<A:
        sL=x-s[i-1]
        sR=s[i]-x
    elif i==0:
        sL=infty
        sR=s[i]-x
    else:
        sL=x-s[-1]
        sR=infty
    
    if 0<j<B:
        tL=x-t[j-1]
        tR=t[j]-x
    elif j==0:
        tL=infty
        tR=t[j]-x
    else:
        tL=x-t[-1]
        tR=infty
    print(min(max(sR,tR),max(sL,tL),sR+tL+min(sR,tL),sL+tR+min(sL,tR)))




Fixed submission:
A,B,Q=map(int,input().split())
inf=1e50
s=[-inf]
for _ in range(A):
    s.append(int(input()))
s.append(inf)

t=[-inf]
for _ in range(B):
    t.append(int(input()))
t.append(inf)
from bisect import bisect

for _ in range(Q):
    x=int(input())
    i=bisect(s,x)
    j=bisect(t,x)
    
    sL=x-s[i-1]
    sR=s[i]-x
    
    tL=x-t[j-1]
    tR=t[j]-x
    print(min(max(sR,tR),max(sL,tL),sR+tL+min(sR,tL),sL+tR+min(sL,tR)))

Buggy python submission (verdict: Time Limit Exceeded):
A,B,Q=map(int,input().split())
s=[]
for _ in range(A):
    s.append(int(input()))
t=[]
for _ in range(B):
    t.append(int(input()))
from bisect import bisect
infty=1e50
for _ in range(Q):
    x=int(input())
    i=bisect(s,x)
    j=bisect(t,x)
    if 0<i<A:
        sL=s[i-1]
        sR=s[i]
    elif i==0:
        sL=-infty
        sR=s[i]
    else:
        sL=s[-1]
        sR=infty
    
    if 0<j<B:
        tL=t[j-1]
        tR=t[j]
    elif j==0:
        tL=-infty
        tR=t[j]
    else:
        tL=t[-1]
        tR=infty
    sL=abs(sL-x)
    sR=abs(sR-x)
    tL=abs(tL-x)
    tR=abs(tR-x)

    print(min(max(sR,tR),max(sL,tL),sR+tL+min(sR,tL),sL+tR+min(sL,tR)))




Fixed submission:
A,B,Q=map(int,input().split())
inf=1e50
s=[-inf]
for _ in range(A):
    s.append(int(input()))
s.append(inf)

t=[-inf]
for _ in range(B):
    t.append(int(input()))
t.append(inf)
from bisect import bisect

for _ in range(Q):
    x=int(input())
    i=bisect(s,x)
    j=bisect(t,x)
    
    sL=x-s[i-1]
    sR=s[i]-x
    
    tL=x-t[j-1]
    tR=t[j]-x
    print(min(max(sR,tR),max(sL,tL),sR+tL+min(sR,tL),sL+tR+min(sL,tR)))