Buggy python submission (verdict: Runtime Error):
import bisect
a,b,q=map(int,input().split())
ls=[-10**11]
lg=[-10**11]
for i in range(a):
  ls.append(int(input()))
for i in range(b):
  lg.append(int(input()))
ls.append(10**11)
lg.append(10**11)
ls=sorted(ls)
lg=sorted(lg)
for i in range(q):
  x=int(input())
  i1=bisect.bisect_left(ls,x)
  i2=bisect.bisect_left(lg,x)#xはi-1~iにある
  l1=[i1,i1+1]
  l2=[i2,i2+1]
  ans1=10**10
  ans2=10**10
  for k in l1:
    for j in l2:
      ans3=abs(x-ls[k])+abs(ls[k]-lg[j])
      if ans3<ans1:
        ans1=ans3
      ans4=abs(x-lg[j])+abs(ls[k]-lg[j])
      if ans4<ans2:
        ans2=ans4
  print(min(ans1,ans2))

Fixed submission:
import bisect
a,b,q=map(int,input().split())
ls=[-10**11]
lg=[-10**11]
for i in range(a):
  ls.append(int(input()))
for i in range(b):
  lg.append(int(input()))
ls.append(10**11)
lg.append(10**11)
ls=sorted(ls)
lg=sorted(lg)
for i in range(q):
  x=int(input())
  i1=bisect.bisect_left(ls,x)
  i2=bisect.bisect_left(lg,x)#xはi-1~iにある
  d1=x-ls[i1-1]
  d2=ls[i1]-x
  d3=x-lg[i2-1]
  d4=lg[i2]-x
  d5=abs(ls[i1-1]-lg[i2-1])
  d6=abs(ls[i1]-lg[i2-1])
  d7=abs(ls[i1-1]-lg[i2])
  d8=abs(ls[i1]-lg[i2])
  ans1=d1+d5
  ans2=d1+d7
  ans3=d2+d6
  ans4=d2+d8
  ans5=d3+d5
  ans6=d3+d6
  ans7=d4+d7
  ans8=d4+d8
  print(min(ans1,ans2,ans3,ans4,ans5,ans6,ans7,ans8))

Buggy python submission (verdict: Runtime Error):
import bisect
a,b,q=map(int,input().split())
ls=[-10**11]
lg=[-10**11]
for i in range(a):
  ls.append(int(input()))
for i in range(b):
  lg.append(int(input()))
ls.append(10**11)
lg.append(10**11)
ls=sorted(ls)
lg=sorted(lg)
for i in range(q):
  x=int(input())
  i1=bisect.bisect_left(ls,x)
  i2=bisect.bisect_left(lg,x)#xはi-1~iにある
  l1=[i1,i1+1]
  l2=[i2,i2+1]
  ans1=10**10
  ans2=10**10
  for i in l1:
    for j in l2:
      ans3=abs(x-ls[i])+abs(ls[i]-lg[j])
      if ans3<ans1:
        ans1=ans3
      ans4=abs(x-lg[j])+abs(ls[i]-lg[j])
      if ans4<ans2:
        ans2=ans4
  print(min(ans1,ans2))

Fixed submission:
import bisect
a,b,q=map(int,input().split())
ls=[-10**11]
lg=[-10**11]
for i in range(a):
  ls.append(int(input()))
for i in range(b):
  lg.append(int(input()))
ls.append(10**11)
lg.append(10**11)
ls=sorted(ls)
lg=sorted(lg)
for i in range(q):
  x=int(input())
  i1=bisect.bisect_left(ls,x)
  i2=bisect.bisect_left(lg,x)#xはi-1~iにある
  d1=x-ls[i1-1]
  d2=ls[i1]-x
  d3=x-lg[i2-1]
  d4=lg[i2]-x
  d5=abs(ls[i1-1]-lg[i2-1])
  d6=abs(ls[i1]-lg[i2-1])
  d7=abs(ls[i1-1]-lg[i2])
  d8=abs(ls[i1]-lg[i2])
  ans1=d1+d5
  ans2=d1+d7
  ans3=d2+d6
  ans4=d2+d8
  ans5=d3+d5
  ans6=d3+d6
  ans7=d4+d7
  ans8=d4+d8
  print(min(ans1,ans2,ans3,ans4,ans5,ans6,ans7,ans8))

Buggy python submission (verdict: Runtime Error):
a,b,q=map(int,input().split())
ls=[]
for i in range(a):
  ls.append(int(input()))
lt=[]
for i in range(b):
  lt.append(int(input()))
def nibutan2(n,l):
  left=0
  right=len(l)-1
  mid=(right+left)//2
  while right>left:
    if l[mid]==n:
      return [0,mid]
    elif l[mid]>n:
      right=mid-1
      mid=(right+left)//2
    else:
      left=mid+1
      mid=(right+left)//2
  if min(abs(l[mid]-n),abs(l[mid-1]-n),abs(l[mid+1]-n))==abs(l[mid]-n):
    return [abs(l[mid]-n),mid]
  elif min(abs(l[mid]-n),abs(l[mid-1]-n),abs(l[mid+1]-n))==abs(l[mid-1]-n):
    return [abs(l[mid-1]-n),mid-1]
  else: 
    return [abs(l[mid+1]-n),mid+1]
for i in range(q):
  n=int(input())
  llt=0
  lls=0
  lltl=nibutann(n,lt)
  llt1=lltl[0]
  llts=lltl[1]
  llt2=nibutann(llts,ls)[0]
  llt=llt1+llt2
  lltl=nibutann(n,ls)
  llt1=lltl[0]
  llts=lltl[1]
  llt2=nibutann(llts,lt)[0]
  lls=llt1+llt2
  print(min(llt,lls))  

Fixed submission:
import bisect
a,b,q=map(int,input().split())
ls=[-10**11]
lg=[-10**11]
for i in range(a):
  ls.append(int(input()))
for i in range(b):
  lg.append(int(input()))
ls.append(10**11)
lg.append(10**11)
ls=sorted(ls)
lg=sorted(lg)
for i in range(q):
  x=int(input())
  i1=bisect.bisect_left(ls,x)
  i2=bisect.bisect_left(lg,x)#xはi-1~iにある
  d1=x-ls[i1-1]
  d2=ls[i1]-x
  d3=x-lg[i2-1]
  d4=lg[i2]-x
  d5=abs(ls[i1-1]-lg[i2-1])
  d6=abs(ls[i1]-lg[i2-1])
  d7=abs(ls[i1-1]-lg[i2])
  d8=abs(ls[i1]-lg[i2])
  ans1=d1+d5
  ans2=d1+d7
  ans3=d2+d6
  ans4=d2+d8
  ans5=d3+d5
  ans6=d3+d6
  ans7=d4+d7
  ans8=d4+d8
  print(min(ans1,ans2,ans3,ans4,ans5,ans6,ans7,ans8))