Buggy python submission (verdict: Time Limit Exceeded):
import bisect

a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]

INF = float('inf')
for _ in range(q):
    x = int(input())
    if x > s[a-1]:
        sl = x - s[a-1]
        sr = INF
    elif x < s[0]:
        sl = INF
        sr = s[0] - x
    else:
        si = bisect.bisect_right(s, x)
        sl = x - s[si-1]
        sr = s[si] - x

    if x > t[b-1]:
        tl = x - t[b-1]
        tr = INF
    elif x < t[0]:
        tl = INF
        tr = t[0] - x
    else:
        ti = bisect.bisect_right(t, x)
        tl = x - t[ti-1]
        tr = t[ti] - x

    ans = min(max(sl, tl), max(sr, tr))

    ans = min(ans, sr*2+tl)
    ans = min(ans, sr+tl*2)
    ans = min(ans, sl*2+tr)
    ans = min(ans, sl+tr*2)

    print(ans)


Fixed submission:
import bisect
import sys
input = sys.stdin.readline

a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]

INF = float('inf')
for _ in range(q):
    x = int(input())
    if x > s[a-1]:
        sl = x - s[a-1]
        sr = INF
    elif x < s[0]:
        sl = INF
        sr = s[0] - x
    else:
        si = bisect.bisect_right(s, x)
        sl = x - s[si-1]
        sr = s[si] - x

    if x > t[b-1]:
        tl = x - t[b-1]
        tr = INF
    elif x < t[0]:
        tl = INF
        tr = t[0] - x
    else:
        ti = bisect.bisect_right(t, x)
        tl = x - t[ti-1]
        tr = t[ti] - x

    ans = min(max(sl, tl), max(sr, tr))

    ans = min(ans, sr*2+tl)
    ans = min(ans, sr+tl*2)
    ans = min(ans, sl*2+tr)
    ans = min(ans, sl+tr*2)

    print(ans)

Buggy python submission (verdict: Runtime Error):
import bisect

a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]

INF = float('inf')
for _ in range(q):
    x = int(input())
    if x > s[a-1]:
        sl = x - s[a-1]
        sr = INF
    elif x < s[0]:
        sl = INF
        sr = s[0] - x
    else:
        si = bisect.bisect_right(s, x)
        sl = x - s[si-1]
        sr = s[si] - x

    if x > t[a-1]:
        tl = x - t[a-1]
        tr = INF
    elif x < t[0]:
        tl = INF
        tr = t[0] - x
    else:
        ti = bisect.bisect_right(t, x)
        tl = x - t[ti-1]
        tr = t[ti] - x

    ans = min(max(sl, tl), max(sr, tr))

    ans = min(ans, sr*2+tl)
    ans = min(ans, sr+tl*2)
    ans = min(ans, sl*2+tr)
    ans = min(ans, sl+tr*2)

    print(ans)


Fixed submission:
import bisect
import sys
input = sys.stdin.readline

a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]

INF = float('inf')
for _ in range(q):
    x = int(input())
    if x > s[a-1]:
        sl = x - s[a-1]
        sr = INF
    elif x < s[0]:
        sl = INF
        sr = s[0] - x
    else:
        si = bisect.bisect_right(s, x)
        sl = x - s[si-1]
        sr = s[si] - x

    if x > t[b-1]:
        tl = x - t[b-1]
        tr = INF
    elif x < t[0]:
        tl = INF
        tr = t[0] - x
    else:
        ti = bisect.bisect_right(t, x)
        tl = x - t[ti-1]
        tr = t[ti] - x

    ans = min(max(sl, tl), max(sr, tr))

    ans = min(ans, sr*2+tl)
    ans = min(ans, sr+tl*2)
    ans = min(ans, sl*2+tr)
    ans = min(ans, sl+tr*2)

    print(ans)