Buggy python submission (verdict: Time Limit Exceeded):
def bisearch(li,target):
    l=0
    r=len(li)-1
    while(l<=r):        
        m=int((l+r)/2)
        if(m==len(li)-1):
            return target-li[m][0]+li[m][1]
        if(li[m][0]<target and target<li[m+1][0]):
            return min(target-li[m][0]+li[m][1],li[m+1][0]-target+li[m+1][1])
        if(m==0 and target<li[0][0]):
            return li[0][0]-target+li[0][1]
        if(target<li[m][0]):
            r = m-1
        else:
            l = m+1

inf = 10**15
A,B,Q = [int(x) for x in input().split()]
s = [0]*(A+1)
t = [0]*(B+1)
x = [0]*Q

for i in range(A):
    s[i] = int(input())
for i in range(B):
    t[i] = int(input())
for i in range(Q):
    x[i] = int(input())
s[-1] = inf
t[-1] = inf

li = []
a = b = 0
while(a<A or b<B):
    if(s[a]<t[b]):
        li.append([s[a],min(abs(t[b]-s[a]),abs(t[b-1]-s[a]))])
        a+=1
    else:
        li.append([t[b],min(abs(t[b]-s[a]),abs(t[b]-s[a-1]))])
        b+=1

for i in x:
    print(bisearch(li,i))


Fixed submission:
def bisearch(li,target):
    l=0
    r=len(li)-1
    while(l<=r):        
        m=int((l+r)/2)
        if(m==len(li)-1):
            return target-li[m][0]+li[m][1]
        if(li[m][0]<target and target<li[m+1][0]):
            return min(target-li[m][0]+li[m][1],li[m+1][0]-target+li[m+1][1])
        if(m==0 and target<li[0][0]):
            return li[0][0]-target+li[0][1]
        if(target<li[m][0]):
            r = m-1
        else:
            l = m+1

inf = 10**15
A,B,Q = [int(x) for x in input().split()]
s = [0]*(A+1)
t = [0]*(B+1)
x = [0]*Q

for i in range(A):
    s[i] = int(input())
for i in range(B):
    t[i] = int(input())
for i in range(Q):
    x[i] = int(input())
s[-1] = inf
t[-1] = inf

li = []
a = b = 0
while(a<A or b<B):
    if(s[a]<t[b]):
        li.append([s[a],min(abs(t[b]-s[a]),abs(t[b-1]-s[a]))])
        a+=1
    else:
        li.append([t[b],min(abs(t[b]-s[a]),abs(t[b]-s[a-1]))])
        b+=1

for i in x:
    print(bisearch(li,i))

Buggy python submission (verdict: Runtime Error):
def bisearch(li,target):
    l=0
    r=len(li)-1
    if(target<li[0][0]):
        return li[m][0]-target+li[m][1]
    if(li[-1][0]<target):
        return target-li[-1][0]+li[-1][1]
    while(l<=r):
        m=int((l+r)/2)
        if(li[m][0]<target and target<li[m+1][0]):
            return min(target-li[m][0]+li[m][1],li[m+1][0]-target+li[m+1][1])
        if(target<li[m][0]):
            r = m-1
        else:
            l = m+1


inf = 10**15
A,B,Q = [int(x) for x in input().split()]
s = [0]*(A+1)
t = [0]*(B+1)
x = [0]*Q


for i in range(A):
    s[i] = int(input())
for i in range(B):
    t[i] = int(input())
for i in range(Q):
    x[i] = int(input())
s[-1] = inf
t[-1] = inf

li = []
a = b = 0
while(a<A or b<B):
    if(s[a]<t[b]):
        li.append([s[a],min(abs(t[b]-s[a]),abs(t[b-1]-s[a]))])
        a+=1
    else:
        li.append([t[b],min(abs(t[b]-s[a]),abs(t[b]-s[a-1]))])
        b+=1
        

for i in x:
    print(bisearch(li,i))

Fixed submission:
def bisearch(li,target):
    l=0
    r=len(li)-1
    while(l<=r):        
        m=int((l+r)/2)
        if(m==len(li)-1):
            return target-li[m][0]+li[m][1]
        if(li[m][0]<target and target<li[m+1][0]):
            return min(target-li[m][0]+li[m][1],li[m+1][0]-target+li[m+1][1])
        if(m==0 and target<li[0][0]):
            return li[0][0]-target+li[0][1]
        if(target<li[m][0]):
            r = m-1
        else:
            l = m+1

inf = 10**15
A,B,Q = [int(x) for x in input().split()]
s = [0]*(A+1)
t = [0]*(B+1)
x = [0]*Q

for i in range(A):
    s[i] = int(input())
for i in range(B):
    t[i] = int(input())
for i in range(Q):
    x[i] = int(input())
s[-1] = inf
t[-1] = inf

li = []
a = b = 0
while(a<A or b<B):
    if(s[a]<t[b]):
        li.append([s[a],min(abs(t[b]-s[a]),abs(t[b-1]-s[a]))])
        a+=1
    else:
        li.append([t[b],min(abs(t[b]-s[a]),abs(t[b]-s[a-1]))])
        b+=1

for i in x:
    print(bisearch(li,i))

Buggy python submission (verdict: Runtime Error):
def bisearch(li,target):
    l=0
    r=len(li)-1
    if(target<li[0][0]):
        return li[m][0]-target+li[m][1]
    elif(li[-1][0]<target):
        return target-li[-1][0]+li[-1][1]
    while(l<=r):
        m=int((l+r)/2)
        if(li[m][0]<target and target<li[m+1][0]):
            return min(target-li[m][0]+li[m][1],li[m+1][0]-target+li[m+1][1])
        if(target<li[m][0]):
            r = m-1
        else:
            l = m+1


inf = 10**15
A,B,Q = [int(x) for x in input().split()]
s = [0]*(A+1)
t = [0]*(B+1)
x = [0]*Q


for i in range(A):
    s[i] = int(input())
for i in range(B):
    t[i] = int(input())
for i in range(Q):
    x[i] = int(input())
s[-1] = inf
t[-1] = inf

li = []
a = b = 0
while(a<A or b<B):
    if(s[a]<t[b]):
        li.append([s[a],min(abs(t[b]-s[a]),abs(t[b-1]-s[a]))])
        a+=1
    else:
        li.append([t[b],min(abs(t[b]-s[a]),abs(t[b]-s[a-1]))])
        b+=1

x.append(500)

for i in x:
    print(bisearch(li,i))


Fixed submission:
def bisearch(li,target):
    l=0
    r=len(li)-1
    while(l<=r):        
        m=int((l+r)/2)
        if(m==len(li)-1):
            return target-li[m][0]+li[m][1]
        if(li[m][0]<target and target<li[m+1][0]):
            return min(target-li[m][0]+li[m][1],li[m+1][0]-target+li[m+1][1])
        if(m==0 and target<li[0][0]):
            return li[0][0]-target+li[0][1]
        if(target<li[m][0]):
            r = m-1
        else:
            l = m+1

inf = 10**15
A,B,Q = [int(x) for x in input().split()]
s = [0]*(A+1)
t = [0]*(B+1)
x = [0]*Q

for i in range(A):
    s[i] = int(input())
for i in range(B):
    t[i] = int(input())
for i in range(Q):
    x[i] = int(input())
s[-1] = inf
t[-1] = inf

li = []
a = b = 0
while(a<A or b<B):
    if(s[a]<t[b]):
        li.append([s[a],min(abs(t[b]-s[a]),abs(t[b-1]-s[a]))])
        a+=1
    else:
        li.append([t[b],min(abs(t[b]-s[a]),abs(t[b]-s[a-1]))])
        b+=1

for i in x:
    print(bisearch(li,i))