Buggy python submission (verdict: Runtime Error):
import numpy as np
A, B, Q=map(int, input().split())
s=[int(input()) for _ in range(A)]
t=[int(input()) for _ in range(B)]
x=[int(input()) for _ in range(Q)]

def f(nums, a):
  if a<=nums[0]:
    return nums[0]-a
  if nums[-1]<=a:
    return a-nums[-1]
  tmp=np.searchsorted(nums, a, side='left')
  return min(a-nums[tmp-1], nums[tmp]-a)

for i in range(Q):
  out=2*10**10
  if x[i]<=s[0]:
    s2=s[0]
    out=min(out, s2-x[i]+f(t, s2))
  elif s[-1]<=x[i]:
    s1=s[-1]
    out=min(out, x[i]-s1+f(t, s1))
  else:
    tmp=np.searchsorted(s, x[i], side='left')
    s1=s[tmp-1]
    out=min(out, x[i]-s1+f(t, s1))
    s2=s[tmp]
    out=min(out, s2-x[i]+f(t, s2))
    
  if x[i]<=t[0]:
    t2=t[0]
    out=min(out, t2-x[i]+f(s, t2))
  elif t[-1]<=x[i]:
    t1=t[-1]
    out=min(out, x[i]-t1+f(s, t1))
  else:
    tmp=np.searchsorted(t, x[i], side='left')
    t1=t[tmp-1]
    out=min(out, x[i]-t1+f(s, t1))
    t2=t[tmp]
    out=min(out, t2-x[i]+f(s, t2))
    
  print(out)

Fixed submission:
import bisect

A, B, Q=map(int, input().split())
s=[int(input()) for _ in range(A)]
t=[int(input()) for _ in range(B)]
x=[int(input()) for _ in range(Q)]

st=[0]*A
ts=[0]*B

for i in range(A):
  tmp=bisect.bisect_left(t, s[i])
  if tmp==0:
    st[i]=t[0]-s[i]
  elif tmp==B:
    st[i]=s[i]-t[-1]
  else:
    st[i]=min(s[i]-t[tmp-1], t[tmp]-s[i])
    
for i in range(B):
  tmp=bisect.bisect_left(s, t[i])
  if tmp==0:
    ts[i]=s[0]-t[i]
  elif tmp==A:
    ts[i]=t[i]-s[-1]
  else:
    ts[i]=min(t[i]-s[tmp-1], s[tmp]-t[i])

for i in range(Q):
  cand=set()
  tmp=bisect.bisect_left(s, x[i])
  if tmp>0:
    cand.add(x[i]-s[tmp-1]+st[tmp-1])
  if tmp<A:
    cand.add(s[tmp]-x[i]+st[tmp])
    
  tmp=bisect.bisect_left(t, x[i])
  if tmp>0:
    cand.add(x[i]-t[tmp-1]+ts[tmp-1])
  if tmp<B:
    cand.add(t[tmp]-x[i]+ts[tmp])
    
  print(min(cand))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
A, B, Q=map(int, input().split())
s=[int(input()) for _ in range(A)]
t=[int(input()) for _ in range(B)]
x=[int(input()) for _ in range(Q)]

def f(nums, a):
  if a<=nums[0]:
    return nums[0]-a
  if nums[-1]<=a:
    return a-nums[-1]
  tmp=np.searchsorted(nums, a, side='left')
  return min(a-nums[tmp-1], nums[tmp]-a)

for i in range(Q):
  out=2*10**10
  if x[i]<=s[0]:
    s2=s[0]
    out=min(out, s2-x[i]+f(t, s2))
  elif s[-1]<=x[i]:
    s1=s[-1]
    out=min(out, x[i]-s1+f(t, s1))
  else:
    tmp=np.searchsorted(s, x[i], side='left')
    s1=s[tmp-1]
    out=min(out, x[i]-s1+f(t, s1))
    s2=s[tmp]
    out=min(out, s2-x[i]+f(t, s2))
    
  if x[i]<=t[0]:
    t2=t[0]
    out=min(out, t2-x[i]+f(s, t2))
  elif t[-1]<=x[i]:
    t1=t[-1]
    out=min(out, x[i]-t1+f(s, t1))
  else:
    tmp=np.searchsorted(t, x[i], side='left')
    t1=t[tmp-1]
    out=min(out, x[i]-t1+f(s, t1))
    t2=t[tmp]
    out=min(out, t2-x[i]+f(s, t2))
    
  print(out)

Fixed submission:
import bisect

A, B, Q=map(int, input().split())
s=[int(input()) for _ in range(A)]
t=[int(input()) for _ in range(B)]
x=[int(input()) for _ in range(Q)]

st=[0]*A
ts=[0]*B

for i in range(A):
  tmp=bisect.bisect_left(t, s[i])
  if tmp==0:
    st[i]=t[0]-s[i]
  elif tmp==B:
    st[i]=s[i]-t[-1]
  else:
    st[i]=min(s[i]-t[tmp-1], t[tmp]-s[i])
    
for i in range(B):
  tmp=bisect.bisect_left(s, t[i])
  if tmp==0:
    ts[i]=s[0]-t[i]
  elif tmp==A:
    ts[i]=t[i]-s[-1]
  else:
    ts[i]=min(t[i]-s[tmp-1], s[tmp]-t[i])

for i in range(Q):
  cand=set()
  tmp=bisect.bisect_left(s, x[i])
  if tmp>0:
    cand.add(x[i]-s[tmp-1]+st[tmp-1])
  if tmp<A:
    cand.add(s[tmp]-x[i]+st[tmp])
    
  tmp=bisect.bisect_left(t, x[i])
  if tmp>0:
    cand.add(x[i]-t[tmp-1]+ts[tmp-1])
  if tmp<B:
    cand.add(t[tmp]-x[i]+ts[tmp])
    
  print(min(cand))