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

A,B,Q=map(int,input().split())

s=[-10**11]
for i in range(A):
    s.append(int(input()))
s.append(10**11)

t=[-10**11]
for i in range(B):
    t.append(int(input()))
t.append(10**11)

for k in range(Q):
    x=int(input())
    i=bi.bisect_left(s,x)
    sl=s[i-1];sr=s[i]
    j=bi.bisect_left(t,x)
    tl=t[j-1];tr=t[j]
    # print(sl,sr,tl,tr)
    print(min(abs(x-sl)+abs(sl-tl),abs(x-sl)+abs(sl-tr),abs(x-sr)+abs(sr-tl),abs(x-sr)+abs(sr-tr),\
        abs(x-tl)+abs(tl-sl),abs(x-tl)+abs(tl-sr),abs(x-tr)+abs(tr-sl),abs(x-tr)+abs(tr-sr)))

Fixed submission:
import bisect as bi

A,B,Q=map(int,input().split())

s=[-10**11]
for i in range(A):
    s.append(int(input()))
s.append(10**11)

t=[-10**11]
for i in range(B):
    t.append(int(input()))
t.append(10**11)

for k in range(Q):
    x=int(input())
    i=bi.bisect_left(s,x)
    sl=s[i-1];sr=s[i]
    j=bi.bisect_left(t,x)
    tl=t[j-1];tr=t[j]
    # print(sl,sr,tl,tr)
    print(min(abs(x-sl)+abs(sl-tl),abs(x-sl)+abs(sl-tr),abs(x-sr)+abs(sr-tl),abs(x-sr)+abs(sr-tr),\
        abs(x-tl)+abs(tl-sl),abs(x-tl)+abs(tl-sr),abs(x-tr)+abs(tr-sl),abs(x-tr)+abs(tr-sr)))

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

def ans(s,t,x):
    i=bi.bisect_left(s,x)
    sl=s[i-1];sr=s[i]
    j=bi.bisect_left(t,x)
    tl=t[j-1];tr=t[j]
    # print(sl,sr,tl,tr)
    return min(abs(x-sl)+abs(sl-tl),abs(x-sl)+abs(sl-tr),abs(x-sr)+abs(sr-tl),abs(x-sr)+abs(sr-tr),\
        abs(x-tl)+abs(tl-sl),abs(x-tl)+abs(tl-sr),abs(x-tr)+abs(tr-sl),abs(x-tr)+abs(tr-sr))

A,B,Q=map(int,input().split())

s=[-10**11]
for i in range(A):
    s.append(int(input()))
s.append(10**11)

t=[-10**11]
for i in range(B):
    t.append(int(input()))
t.append(10**11)

for i in range(Q):
    print(ans(s,t,int(input())))

Fixed submission:
import bisect as bi

A,B,Q=map(int,input().split())

s=[-10**11]
for i in range(A):
    s.append(int(input()))
s.append(10**11)

t=[-10**11]
for i in range(B):
    t.append(int(input()))
t.append(10**11)

for k in range(Q):
    x=int(input())
    i=bi.bisect_left(s,x)
    sl=s[i-1];sr=s[i]
    j=bi.bisect_left(t,x)
    tl=t[j-1];tr=t[j]
    # print(sl,sr,tl,tr)
    print(min(abs(x-sl)+abs(sl-tl),abs(x-sl)+abs(sl-tr),abs(x-sr)+abs(sr-tl),abs(x-sr)+abs(sr-tr),\
        abs(x-tl)+abs(tl-sl),abs(x-tl)+abs(tl-sr),abs(x-tr)+abs(tr-sl),abs(x-tr)+abs(tr-sr)))

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

def dL(x,li):
    ind=bi.bisect_left(li,x)
    if ind==0:
        return 10**11
    else:
        return x-li[ind-1]

def dR(x,li):
    ind=bi.bisect_left(li,x)
    if ind==len(li):
        return 10**11
    else:
        return li[ind]-x

def ans(x,s,t):
    dLs=dL(x,s);dRs=dR(x,s)
    dLt=dL(x,t);dRt=dR(x,t)
    # 西の神社から訪ねる(d1)
    d1=dLs
    if dLs<dLt:
        d1+=min(toLt[x-dLs],toRt[x-dLs])
    d2=dRs
    if dRs<dRt:
        d2+=min(toLt[x+dRs],toRt[x+dRs])
    d3=dLt
    if dLt<dLs:
        d3+=min(toLs[x-dLt],toRs[x-dLt])
    d4=dR(x,t)
    if dRt<dRs:
        d4+=min(toLs[x+dRt],toRs[x+dRt])
    
    return min(d1,d2,d3,d4)

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()))

# 各神社の座標につき，東西の最寄りの寺までの距離を計算しておく
toLt={};toRt={}
for i in range(A):
    toLt[s[i]]=dL(s[i],t)
    toRt[s[i]]=dR(s[i],t)
# 同上
toLs={};toRs={}
for i in range(B):
    toLs[t[i]]=dL(t[i],s)
    toRs[t[i]]=dR(t[i],s)

for i in range(Q):
    print(ans(int(input()),s,t))

Fixed submission:
import bisect as bi

A,B,Q=map(int,input().split())

s=[-10**11]
for i in range(A):
    s.append(int(input()))
s.append(10**11)

t=[-10**11]
for i in range(B):
    t.append(int(input()))
t.append(10**11)

for k in range(Q):
    x=int(input())
    i=bi.bisect_left(s,x)
    sl=s[i-1];sr=s[i]
    j=bi.bisect_left(t,x)
    tl=t[j-1];tr=t[j]
    # print(sl,sr,tl,tr)
    print(min(abs(x-sl)+abs(sl-tl),abs(x-sl)+abs(sl-tr),abs(x-sr)+abs(sr-tl),abs(x-sr)+abs(sr-tr),\
        abs(x-tl)+abs(tl-sl),abs(x-tl)+abs(tl-sr),abs(x-tr)+abs(tr-sl),abs(x-tr)+abs(tr-sr)))

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

def L(x,l):
    return x-l[bi.bisect_left(l,x)-1]

def R(x,l):
    return l[bi.bisect_left(l,x)]-x

def ans(x):
    global s;global t
    
    # 西の神社から訪ねる(d1)
    d1=dLs=L(x,s);dLt=L(x,t)
    if dLt>dLs:
        d1+=min(L(x-dLs,t),R(x-dLs,t))
    
    d2=dRs=R(x,s);dRt=R(x,t)
    if dRt>dRs:
        d2+=min(L(x+dRs,t),R(x+dRs,t))
    
    d3=dLt
    if dLs>dLt:
        d3+=min(L(x-dLt,s),R(x-dLt,s))
    
    d4=dRt
    if dRs>dRt:
        d4+=min(L(x+dRt,s),R(x+dRt,s))
    
    return min(d1,d2,d3,d4)

A,B,Q=map(int,input().split())
s=[-10**10]
for i in range(A):
    s.append(int(input()))
s.append(2*10**10)

t=[-10**10]
for i in range(B):
    t.append(int(input()))
t.append(2*10**10)

for i in range(Q):
    print(ans(int(input())))

Fixed submission:
import bisect as bi

A,B,Q=map(int,input().split())

s=[-10**11]
for i in range(A):
    s.append(int(input()))
s.append(10**11)

t=[-10**11]
for i in range(B):
    t.append(int(input()))
t.append(10**11)

for k in range(Q):
    x=int(input())
    i=bi.bisect_left(s,x)
    sl=s[i-1];sr=s[i]
    j=bi.bisect_left(t,x)
    tl=t[j-1];tr=t[j]
    # print(sl,sr,tl,tr)
    print(min(abs(x-sl)+abs(sl-tl),abs(x-sl)+abs(sl-tr),abs(x-sr)+abs(sr-tl),abs(x-sr)+abs(sr-tr),\
        abs(x-tl)+abs(tl-sl),abs(x-tl)+abs(tl-sr),abs(x-tr)+abs(tr-sl),abs(x-tr)+abs(tr-sr)))