Buggy python submission (verdict: Runtime Error):
a,b,q = map(int,input().split())
s = [-float('inf')]+[int(input()) for i in range(a)]+[float('inf')]
t = [-float('inf')]+[int(input()) for i in range(b)]+[float('inf')]
x = [int(input()) for i in range(q)]
import bisect
for x_ in x:
    s_r = bisect.bisect_right(s,x_)
    t_r = bisect.bisect_right(s,x_)
    res = float('inf')
    for S in [s[s_r-1],s[s_r]]:
        for T in [t[t_r-1],t[t_r]]:
            d1 = abs(S-x_)+abs(T-S)
            d2 = abs(T-x_)+abs(S-T)
            res = min(res,d1,d2)
    print(res)

Fixed submission:
a,b,q = map(int,input().split())
s = [-float('inf')]+[int(input()) for i in range(a)]+[float('inf')]
t = [-float('inf')]+[int(input()) for i in range(b)]+[float('inf')]
x = [int(input()) for i in range(q)]
import bisect
for x_ in x:
    s_r = bisect.bisect_right(s,x_)
    t_r = bisect.bisect_right(t,x_)
    res = float('inf')
    for S in [s[s_r-1],s[s_r]]:
        for T in [t[t_r-1],t[t_r]]:
            d1 = abs(S-x_)+abs(T-S)
            d2 = abs(T-x_)+abs(S-T)
            res = min(res,d1,d2)
    print(res)

Buggy python submission (verdict: Runtime Error):
a,b,q = map(int,input().split())
s = [-float('inf')]+[int(input()) for i in range(a)]+[float('inf')]
t = [-float('inf')]+[int(input()) for i in range(b)]+[float('inf')]
x = [int(input()) for i in range(q)]
import bisect
for x_ in x:
    s_r = bisect.bisect_right(s,x_)
    t_r = bisect.bisect_right(s,x_)
    res = INF
    for S in [s[s_r-1],s[s_r]]:
        for T in [t[t_r-1],t[t_r]]:
            d1 = abs(S-x_)+abs(T-S)
            d2 = abs(T-x_)+abs(S-T)
            res = min(res,d1,d2)
    print(res)

for ans_ in ans:
    print(ans_)

Fixed submission:
a,b,q = map(int,input().split())
s = [-float('inf')]+[int(input()) for i in range(a)]+[float('inf')]
t = [-float('inf')]+[int(input()) for i in range(b)]+[float('inf')]
x = [int(input()) for i in range(q)]
import bisect
for x_ in x:
    s_r = bisect.bisect_right(s,x_)
    t_r = bisect.bisect_right(t,x_)
    res = float('inf')
    for S in [s[s_r-1],s[s_r]]:
        for T in [t[t_r-1],t[t_r]]:
            d1 = abs(S-x_)+abs(T-S)
            d2 = abs(T-x_)+abs(S-T)
            res = min(res,d1,d2)
    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
a,b,q = map(int,input().split())
s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]
x = [int(input()) for i in range(q)]
ans = []
for x_ in x:
    s_ = []
    t_ = []
    for i in range(len(s)):
        s_.append(s[i]-x_)
    for i in range(len(t)):
        t_.append(t[i]-x_)
    s_l=-float('inf')
    s_r=float('inf')
    t_l=-float('inf')
    t_r=float('inf')
    for k in s_:
        if k<0:
            s_l=k
        else:
            s_r=k
            break
    for k in t_:
        if k<0:
            t_l=k
        else:
            t_r=k
            break
    ans.append(min(max(abs(s_l),abs(t_l)),abs(s_l)*2+t_r,t_r*2+abs(s_l),max(s_r,t_r),s_r*2+abs(t_l),abs(t_l)*2+s_r))
for ans_ in ans:
    print(ans_)


Fixed submission:
a,b,q = map(int,input().split())
s = [-float('inf')]+[int(input()) for i in range(a)]+[float('inf')]
t = [-float('inf')]+[int(input()) for i in range(b)]+[float('inf')]
x = [int(input()) for i in range(q)]
import bisect
for x_ in x:
    s_r = bisect.bisect_right(s,x_)
    t_r = bisect.bisect_right(t,x_)
    res = float('inf')
    for S in [s[s_r-1],s[s_r]]:
        for T in [t[t_r-1],t[t_r]]:
            d1 = abs(S-x_)+abs(T-S)
            d2 = abs(T-x_)+abs(S-T)
            res = min(res,d1,d2)
    print(res)