Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import bisect_left
#inpurt = sys.stdin.readline
a, b, q = map(int, input().split())
INF = 10 ** 11
s = [-INF]
#s_append = s.append
for i in range(a):
    si = int(input())
    s.append(si)
s.append(INF)
t = [-INF]
#t_append = t.append
for i in range(b):
    ti = int(input())
    t.append(ti)
t.append(INF)
x = []
#x_append = x.append
for i in range(q):
    xi = int(input())
    x.append(xi)

for xi in x:
    index_s = bisect_left(s, xi)
    s1 = xi - s[index_s - 1]
    s2 = s[index_s] - xi
    index_t = bisect_left(t, xi)
    t1 = xi - t[index_t - 1]
    t2 = t[index_t] -xi
    print(min(max(s1, t1), max(s2, t2), min(s1, t2) * 2 + max(s1, t2), min(s2, t1) * 2 + max(s2, t1)))


Fixed submission:
import bisect
import sys
input = sys.stdin.readline
A, B, Q = list(map(int, input().split()))
s = [int(input()) for i in range(A)]
t = [int(input()) for i in range(B)]
s.append(-100000000000);s.append(100000000000)
t.append(-100000000000);t.append(100000000000)
s = sorted(s, reverse=False)
t = sorted(t, reverse=False)

for i in range(Q):
    xi = int(input())
    sr = s[bisect.bisect_left(s, xi)]
    sl = s[bisect.bisect_left(s, xi) - 1]
    tr = t[bisect.bisect_left(t, xi)]
    tl = t[bisect.bisect_left(t, xi) - 1]

    ans = min(max(sr, tr) - xi, xi - min(sl, tl),
              tr - sl + min(tr - xi, xi - sl), sr - tl + min(sr - xi, xi - tl))
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import bisect_left
#inpurt = sys.stdin.readline
a, b, q = map(int, input().split())
INF = 10 ** 11
s = [-INF]
s_append = s.append
for i in range(a):
    si = int(input())
    s_append(si)
s_append(INF)
t = [-INF]
#t_append = t.append
for i in range(b):
    ti = int(input())
    t.append(ti)
t.append(INF)
x = []
#x_append = x.append
for i in range(q):
    xi = int(input())
    x.append(xi)

for xi in x:
    index_s = bisect_left(s, xi)
    s1 = xi - s[index_s - 1]
    s2 = s[index_s] - xi
    index_t = bisect_left(t, xi)
    t1 = xi - t[index_t - 1]
    t2 = t[index_t] -xi
    print(min(max(s1, t1), max(s2, t2), min(s1, t2) * 2 + max(s1, t2), min(s2, t1) * 2 + max(s2, t1)))


Fixed submission:
import bisect
import sys
input = sys.stdin.readline
A, B, Q = list(map(int, input().split()))
s = [int(input()) for i in range(A)]
t = [int(input()) for i in range(B)]
s.append(-100000000000);s.append(100000000000)
t.append(-100000000000);t.append(100000000000)
s = sorted(s, reverse=False)
t = sorted(t, reverse=False)

for i in range(Q):
    xi = int(input())
    sr = s[bisect.bisect_left(s, xi)]
    sl = s[bisect.bisect_left(s, xi) - 1]
    tr = t[bisect.bisect_left(t, xi)]
    tl = t[bisect.bisect_left(t, xi) - 1]

    ans = min(max(sr, tr) - xi, xi - min(sl, tl),
              tr - sl + min(tr - xi, xi - sl), sr - tl + min(sr - xi, xi - tl))
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
A, B, Q = list(map(int, input().split()))
s = [int(input()) for i in range(A)]
t = [int(input()) for i in range(B)]
s.append(-100000000000);s.append(100000000000)
t.append(-100000000000);t.append(100000000000)
s = sorted(s, reverse=False)
t = sorted(t, reverse=False)
sn = np.array(s)
tn = np.array(t)

for i in range(Q):
    xi = int(input())
    sr = sn[sn.searchsorted(xi)]
    sl = sn[sn.searchsorted(xi) - 1]
    tr = tn[tn.searchsorted(xi)]
    tl = tn[tn.searchsorted(xi) - 1]

    ans = min(max(sr, tr) - xi, xi - min(sl, tl),
              tr - sl + min(tr - xi, xi - sl), sr - tl + min(sr - xi, xi - tl))
    print(ans)


Fixed submission:
import bisect
import sys
input = sys.stdin.readline
A, B, Q = list(map(int, input().split()))
s = [int(input()) for i in range(A)]
t = [int(input()) for i in range(B)]
s.append(-100000000000);s.append(100000000000)
t.append(-100000000000);t.append(100000000000)
s = sorted(s, reverse=False)
t = sorted(t, reverse=False)

for i in range(Q):
    xi = int(input())
    sr = s[bisect.bisect_left(s, xi)]
    sl = s[bisect.bisect_left(s, xi) - 1]
    tr = t[bisect.bisect_left(t, xi)]
    tl = t[bisect.bisect_left(t, xi) - 1]

    ans = min(max(sr, tr) - xi, xi - min(sl, tl),
              tr - sl + min(tr - xi, xi - sl), sr - tl + min(sr - xi, xi - tl))
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
A, B, Q = list(map(int, input().split()))
s = [int(input()) for i in range(A)]
t = [int(input()) for i in range(B)]
s.append(-100000000000);s.append(100000000000)
t.append(-100000000000);t.append(100000000000)
s = sorted(s, reverse=False)
t = sorted(t, reverse=False)
sn = np.array(s)
tn = np.array(t)

for i in range(Q):
    xi = int(input())
    sr = sn[sn.searchsorted(xi)]
    sl = sn[sn.searchsorted(xi) - 1]
    tr = tn.searchsorted(sn[sn.searchsorted(xi)])
    tl = tn.searchsorted(sn[sn.searchsorted(xi) - 1])

    stot = min(abs(xi - sr) + abs(sr - tn[tr]), abs(xi - sr) + abs(sr - tn[tr - 1]),
               abs(xi - sl) + abs(sl - tn[tl]), abs(xi - sl) + abs(sl - tn[tl - 1]))

    tr = tn[tn.searchsorted(xi)]
    tl = tn[tn.searchsorted(xi) - 1]
    sr = sn.searchsorted(tn[tn.searchsorted(xi)])
    sl = sn.searchsorted(tn[tn.searchsorted(xi) - 1])

    ttos = min(abs(xi - tr) + abs(tr - sn[sr]), abs(xi - tr) + abs(tr - sn[sr - 1]),
               abs(xi - tl) + abs(tl - sn[sl]), abs(xi - tl) + abs(tl - sn[sl - 1]))
    print(min(stot, ttos))

Fixed submission:
import bisect
import sys
input = sys.stdin.readline
A, B, Q = list(map(int, input().split()))
s = [int(input()) for i in range(A)]
t = [int(input()) for i in range(B)]
s.append(-100000000000);s.append(100000000000)
t.append(-100000000000);t.append(100000000000)
s = sorted(s, reverse=False)
t = sorted(t, reverse=False)

for i in range(Q):
    xi = int(input())
    sr = s[bisect.bisect_left(s, xi)]
    sl = s[bisect.bisect_left(s, xi) - 1]
    tr = t[bisect.bisect_left(t, xi)]
    tl = t[bisect.bisect_left(t, xi) - 1]

    ans = min(max(sr, tr) - xi, xi - min(sl, tl),
              tr - sl + min(tr - xi, xi - sl), sr - tl + min(sr - xi, xi - tl))
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
A, B, Q = list(map(int, input().split()))
s = []
t = []
s.append(-100000000000)
s.append(100000000000)
t.append(-100000000000)
t.append(100000000000)
for i in range(A):
    s.append(int(input()))
s = sorted(s, reverse=False)
sn = np.array(s)
for i in range(B):
    t.append(int(input()))
t = sorted(t, reverse=False)
tn = np.array(t)
for i in range(Q):
    xi = int(input())

    stot = min(abs(xi - sn[sn.searchsorted(xi)])
               + abs(sn[sn.searchsorted(xi)] - tn[tn.searchsorted(sn[sn.searchsorted(xi)])]),
               abs(xi - sn[sn.searchsorted(xi)])
               + abs(sn[sn.searchsorted(xi)] - tn[tn.searchsorted(sn[sn.searchsorted(xi)]) - 1]),
               abs(xi - sn[sn.searchsorted(xi) - 1])
               + abs(sn[sn.searchsorted(xi) - 1] - tn[tn.searchsorted(sn[sn.searchsorted(xi) - 1])]),
               abs(xi - sn[sn.searchsorted(xi) - 1])
               + abs(sn[sn.searchsorted(xi) - 1] - tn[tn.searchsorted(sn[sn.searchsorted(xi) - 1]) - 1])
               )
    ttos = min(abs(xi - tn[tn.searchsorted(xi)])
               + abs(tn[tn.searchsorted(xi)] - sn[sn.searchsorted(tn[tn.searchsorted(xi)])]),
               abs(xi - tn[tn.searchsorted(xi)])
               + abs(tn[tn.searchsorted(xi)] - sn[sn.searchsorted(tn[tn.searchsorted(xi)]) - 1]),
               abs(xi - tn[tn.searchsorted(xi) - 1])
               + abs(tn[tn.searchsorted(xi) - 1] - sn[sn.searchsorted(tn[tn.searchsorted(xi) - 1])]),
               abs(xi - tn[tn.searchsorted(xi) - 1])
               + abs(tn[tn.searchsorted(xi) - 1] - sn[sn.searchsorted(tn[tn.searchsorted(xi) - 1]) - 1])
               )
    print(min(stot, ttos))


Fixed submission:
import bisect
import sys
input = sys.stdin.readline
A, B, Q = list(map(int, input().split()))
s = [int(input()) for i in range(A)]
t = [int(input()) for i in range(B)]
s.append(-100000000000);s.append(100000000000)
t.append(-100000000000);t.append(100000000000)
s = sorted(s, reverse=False)
t = sorted(t, reverse=False)

for i in range(Q):
    xi = int(input())
    sr = s[bisect.bisect_left(s, xi)]
    sl = s[bisect.bisect_left(s, xi) - 1]
    tr = t[bisect.bisect_left(t, xi)]
    tl = t[bisect.bisect_left(t, xi) - 1]

    ans = min(max(sr, tr) - xi, xi - min(sl, tl),
              tr - sl + min(tr - xi, xi - sl), sr - tl + min(sr - xi, xi - tl))
    print(ans)