Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
A,B,Q=map(int,input().split())

def bisearch(target,lis):
    low=0
    high=len(lis)-1
    if lis[0]>target:
        return low-1
    elif lis[-1]<target:
        return high
    
    while lis[low]>target or lis[low+1]<target:
        mid=(low+high)//2
        if lis[mid]<target:
            high=mid
        else:
            low=mid
    return low

def cand(num,lis):
    N=len(lis)-1
    a=max(num,0)
    b=min(num+1,N)
    return [lis[a],lis[b]]

god=[]
for _ in range(A):
    god.append(int(input()))

buddha=[]
for _ in range(B):
    buddha.append(int(input()))

for _ in range(Q):
    q=int(input())
    g_i=(bisearch(q,god))
    b_i=(bisearch(q,buddha))
    G=cand(g_i,god)
    B=cand(b_i,buddha)
    ans=10**18
    ans=min(abs(q-G[0])+abs(G[0]-B[0]),abs(q-B[0])+abs(B[0]-G[0]),abs(q-G[1])+abs(G[1]-B[0]),abs(q-B[0])+abs(B[0]-G[1]),abs(q-G[0])+abs(G[0]-B[1]),abs(q-B[1])+abs(B[1]-G[0]),abs(q-G[1])+abs(G[1]-B[1]),abs(q-B[1])+abs(B[1]-G[1]))
    for g in G:
        for b in B:
            ans=min(ans,abs(q-g)+abs(g-b),abs(q-b)+abs(b-g))
    print(ans)


Fixed submission:
# coding: utf-8
# Your code here!
import bisect

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

god=[-10**18]
for _ in range(A):
    god.append(int(input()))
god.append(10**18)

buddha=[-10**18]
for _ in range(B):
    buddha.append(int(input()))
buddha.append(10**18)

#print(god,buddha)
for _ in range(Q):
    q=int(input())
    g_i=bisect.bisect_left(god, q)
    b_i=bisect.bisect_left(buddha, q)
    #print(g_i,b_i)
    
    ans=10**18
    G=[god[g_i-1],god[g_i]]
    B=[buddha[b_i-1],buddha[b_i]]
    for g in G:
        for b in B:
            ans=min(ans,abs(q-g)+abs(g-b),abs(q-b)+abs(b-g))
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
A,B,Q=map(int,input().split())

def bisearch(target,lis):
    low=0
    high=len(lis)-1
    if lis[0]>target:
        return low-1
    elif lis[-1]<target:
        return high
    
    while lis[low]>target or lis[low+1]<target:
        mid=(low+high)//2
        if lis[mid]<target:
            high=mid
        else:
            low=mid
    return low

def cand(num,lis):
    N=len(lis)-1
    a=max(num,0)
    b=min(num+1,N)
    return [lis[a],lis[b]]

god=[]
for _ in range(A):
    god.append(int(input()))

buddha=[]
for _ in range(B):
    buddha.append(int(input()))

for _ in range(Q):
    q=int(input())
    g_i=(bisearch(q,god))
    b_i=(bisearch(q,buddha))
    G=cand(g_i,god)
    B=cand(b_i,buddha)
    ans=10**18
    for g in G:
        for b in B:
            ans=min(ans,abs(q-g)+abs(g-b),abs(q-b)+abs(b-g))
    print(ans)


Fixed submission:
# coding: utf-8
# Your code here!
import bisect

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

god=[-10**18]
for _ in range(A):
    god.append(int(input()))
god.append(10**18)

buddha=[-10**18]
for _ in range(B):
    buddha.append(int(input()))
buddha.append(10**18)

#print(god,buddha)
for _ in range(Q):
    q=int(input())
    g_i=bisect.bisect_left(god, q)
    b_i=bisect.bisect_left(buddha, q)
    #print(g_i,b_i)
    
    ans=10**18
    G=[god[g_i-1],god[g_i]]
    B=[buddha[b_i-1],buddha[b_i]]
    for g in G:
        for b in B:
            ans=min(ans,abs(q-g)+abs(g-b),abs(q-b)+abs(b-g))
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
A,B,Q=map(int,input().split())

def bisearch(target,lis):
    low=0
    high=len(lis)-1
    if lis[0]>target:
        return low-1
    elif lis[-1]<target:
        return high
    
    while lis[low]>target or lis[low+1]<target:
        mid=(low+high)//2
        if lis[mid]<target:
            high=mid
        else:
            low=mid
    return low

def cand(num,lis):
    N=len(lis)-1
    a=max(num,0)
    b=min(num+1,N)
    return [lis[a],lis[b]]

god=[]
for _ in range(A):
    god.append(int(input()))

buddha=[]
for _ in range(B):
    buddha.append(int(input()))

for _ in range(Q):
    q=int(input())
    g_i=(bisearch(q,god))
    b_i=(bisearch(q,buddha))
    G=cand(g_i,god)
    B=cand(b_i,buddha)
    ans=10**18
    for g in G:
        for b in B:
            ans=min(ans,abs(q-g)+abs(g-b),abs(q-b)+abs(b-g))
    print(ans)


Fixed submission:
# coding: utf-8
# Your code here!
import bisect

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

god=[-10**18]
for _ in range(A):
    god.append(int(input()))
god.append(10**18)

buddha=[-10**18]
for _ in range(B):
    buddha.append(int(input()))
buddha.append(10**18)

#print(god,buddha)
for _ in range(Q):
    q=int(input())
    g_i=bisect.bisect_left(god, q)
    b_i=bisect.bisect_left(buddha, q)
    #print(g_i,b_i)
    
    ans=10**18
    G=[god[g_i-1],god[g_i]]
    B=[buddha[b_i-1],buddha[b_i]]
    for g in G:
        for b in B:
            ans=min(ans,abs(q-g)+abs(g-b),abs(q-b)+abs(b-g))
    print(ans)