Buggy python submission (verdict: Time Limit Exceeded):
a,b,q = list(map(int,input().split()))
s = [int(input()) for i in range(0,a)]
t = [int(input()) for i in range(0,b)]
x = [int(input()) for i in range(0,q)]

s.sort()
t.sort()

def bifind(r,z):
    low = 0
    high = len(r)-1
    y = (low + high)//2
    if z < r[0]:
        return [r[0],r[0]]
    elif z > r[-1]:
        return [r[-1],r[-1]]
    while True:
        if r[y] <= z:
            low = y
            y = (y+high)//2
        else:
            high = y
            y = (low + y)//2
        if r[y] < z < r[y+1]:
            break
    return [r[y],r[y+1]]

for i in range(0,q):
    ls = bifind(s,x[i])
    lt = bifind(t,x[i])
    ans = list()
    for j in range(0,2):
        for k in range(0,2):
            ans.append(abs(ls[j]-x[i])+abs(lt[k]-ls[j]))
            ans.append(abs(lt[k]-x[i])+abs(lt[k]-ls[j]))
    print(min(ans))

Fixed submission:
a,b,q = list(map(int,input().split()))
s = [int(input()) for i in range(0,a)]
t = [int(input()) for i in range(0,b)]
x = [int(input()) for i in range(0,q)]
import bisect

def bifind(r,z):
    if z < r[0]:
        return [r[0],r[0]]
    elif z > r[-1]:
        return [r[-1],r[-1]]
    y = bisect.bisect_left(r,z)-1
    return [r[y],r[y+1]]

for i in range(0,q):
    ls = bifind(s,x[i])
    lt = bifind(t,x[i])
    ans = list()
    for j in range(0,2):
        for k in range(0,2):
            ans.append(abs(ls[j]-x[i])+abs(lt[k]-ls[j]))
            ans.append(abs(lt[k]-x[i])+abs(lt[k]-ls[j]))
    print(min(ans))

Buggy python submission (verdict: Time Limit Exceeded):
a,b,q = list(map(int,input().split()))
s = [int(input()) for i in range(0,a)]
t = [int(input()) for i in range(0,b)]
x = [int(input()) for i in range(0,q)]

s.sort()
t.sort()

def bifind(r,z):
    y = len(r)//2
    halftime = 2
    if z < r[0]:
        return [r[0],r[0]]
    elif z > r[-1]:
        return [r[-1],r[-1]]
    while True:
        if r[y] <= z:
            y += len(r)//(2**halftime)+1
        else:
            y -= len(r)//(2**halftime)+1
        halftime += 1
        if y+1  >= len(r):
            y = len(r)-2
        if y  < 0:
            y = 0
        if r[y] < z < r[y+1]:
            break
    return [r[y],r[y+1]]

for i in range(0,q):
    ls = bifind(s,x[i])
    lt = bifind(t,x[i])
    ans = list()
    for j in range(0,2):
        for k in range(0,2):
            ans.append(abs(ls[j]-x[i])+abs(lt[k]-ls[j]))
            ans.append(abs(lt[k]-x[i])+abs(lt[k]-ls[j]))
    print(min(ans))

Fixed submission:
a,b,q = list(map(int,input().split()))
s = [int(input()) for i in range(0,a)]
t = [int(input()) for i in range(0,b)]
x = [int(input()) for i in range(0,q)]
import bisect

def bifind(r,z):
    if z < r[0]:
        return [r[0],r[0]]
    elif z > r[-1]:
        return [r[-1],r[-1]]
    y = bisect.bisect_left(r,z)-1
    return [r[y],r[y+1]]

for i in range(0,q):
    ls = bifind(s,x[i])
    lt = bifind(t,x[i])
    ans = list()
    for j in range(0,2):
        for k in range(0,2):
            ans.append(abs(ls[j]-x[i])+abs(lt[k]-ls[j]))
            ans.append(abs(lt[k]-x[i])+abs(lt[k]-ls[j]))
    print(min(ans))

Buggy python submission (verdict: Time Limit Exceeded):
a,b,q = list(map(int,input().split()))
s = [int(input()) for i in range(0,a)]
t = [int(input()) for i in range(0,b)]
x = [int(input()) for i in range(0,q)]

s.sort()
t.sort()

def bifind(r,z):
    y = len(r)//2
    halftime = 2
    if z < r[0]:
        return [10**11,r[0]]
    elif z > r[-1]:
        return [r[-1],10**11]
    while True:
        if r[y] <= z:
            y += len(r)//(2**halftime)+1
        else:
            y -= len(r)//(2**halftime)+1
        halftime += 1
        if y+1  >= len(r):
            y = len(r)-2
        if y  < 0:
            y = 0
        if r[y] < z < r[y+1]:
            break
    return [r[y],r[y+1]]

for i in range(0,q):
    ls = bifind(s,x[i])
    lt = bifind(t,x[i])
    ans = 10**11
    for j in range(0,2):
        for k in range(0,2):
            ans = min(ans,abs(ls[j]-x[i])+abs(lt[k]-ls[j]))
            ans = min(ans,abs(lt[k]-x[i])+abs(lt[k]-ls[j]))
    print(ans)

Fixed submission:
a,b,q = list(map(int,input().split()))
s = [int(input()) for i in range(0,a)]
t = [int(input()) for i in range(0,b)]
x = [int(input()) for i in range(0,q)]
import bisect

def bifind(r,z):
    if z < r[0]:
        return [r[0],r[0]]
    elif z > r[-1]:
        return [r[-1],r[-1]]
    y = bisect.bisect_left(r,z)-1
    return [r[y],r[y+1]]

for i in range(0,q):
    ls = bifind(s,x[i])
    lt = bifind(t,x[i])
    ans = list()
    for j in range(0,2):
        for k in range(0,2):
            ans.append(abs(ls[j]-x[i])+abs(lt[k]-ls[j]))
            ans.append(abs(lt[k]-x[i])+abs(lt[k]-ls[j]))
    print(min(ans))