Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect
import numpy as np
a,b,q = map(int, input().split())
s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]

for _ in range(q):
    x = int(input())
    # print('x', x)
    ss = bisect(s, x)
    tt = bisect(t, x)
    tmp = []
    if ss > 0 and tt > 0:
        i = abs(s[ss-1] - x)
        j = abs(t[tt-1] - x)
        if sorted([s[ss-1], x, t[tt-1]]).index(x) == 1:
            # print(i+j+min(i,j), s[ss-1], t[tt-1])
            tmp.append(np.sum([i,j,min(i,j)]))
        else:
            # print((i-j), s[ss-1], t[tt-1])
            tmp.append(max(i,j))
    if 0 < ss and tt < b:
        i = abs(s[ss-1] - x)
        j = abs(t[tt] - x)
        if sorted([s[ss-1], x, t[tt]]).index(x) == 1:
            tmp.append(np.sum([i,j,min(i,j)]))
        else:
            tmp.append(max(i,j))
    if ss < a and tt > 0:
        i = abs(s[ss] - x)
        j = abs(t[tt-1] - x)
        if sorted([s[ss], x, t[tt-1]]).index(x) == 1:
            # print(i+j+min(i,j), s[ss], t[tt-1])
            tmp.append(np.sum([i,j,min(i,j)]))
        else:
            # print(i-j, s[ss], t[tt-1])
            tmp.append(max(i,j))
    if ss < a and tt < b:
        i = abs(s[ss] - x)
        j = abs(t[tt] - x)
        if sorted([s[ss], x, t[tt]]).index(x) == 1:
            # print(i+j+min(i,j), s[ss], t[tt])
            tmp.append(np.sum([i,j,min(i,j)]))
        else:
            # print(i-j, s[ss], t[tt])
            tmp.append(max(i,j))
    # print(tmp, ss, tt)
    print(min(tmp))



Fixed submission:
from bisect import bisect
a,b,q = map(int, input().split())
s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]

inf = float('INF')
for _ in range(q):
    x = int(input())
    # print('x', x)
    ss = bisect(s, x)
    tt = bisect(t, x)
    ans = inf
    for i in range(max(ss-1,0),min(ss+1,a)):
        for j in range(max(tt-1,0),min(tt+1,b)):
            ii,jj = abs(s[i] - x) + abs(s[i] - t[j]), abs(t[j] - x) + abs(s[i] - t[j])
            tmp = min(ii,jj)
            if ans > tmp:
                ans = tmp
    print(ans)

Buggy python submission (verdict: Runtime Error):
from bisect import bisect
# import numpy as np
a,b,q = map(int, input().split())
s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]
inf = float('INF')

for _ in range(q):
    x = int(input())
    # print('x', x)
    ss = bisect(s, x)
    tt = bisect(t, x)
    ans = inf
    # print(s[min(ss,a-1)], t[min(tt,b-1)], x)
    j,l = abs(t[max(tt-1,0)] - x), abs(t[min(b-1,tt)] - x)
    if ss :
        i = abs(s[ss-1] - x)
        if tt :
            if sorted([s[ss-1], x, t[tt-1]]).index(x) == 1:
                if ans > i+j+min(i,j):
                    ans = i+j+min(i,j)
            else:
                if ans > max(i,j):
                    ans = max(i,j)
        if tt < b:
            if sorted([s[ss-1], x, t[tt]]).index(x) == 1:
                if ans > i+l+min(i,l):
                    ans = i+l+min(i,l)
            else:
                if ans > max(i,l):
                    ans = max(i,l)
    if ss < a:
        k = abs(s[ss] - x)
        if tt:
            if sorted([s[ss], x, t[tt-1]]).index(x) == 1:
                if ans > i+j+min(k,j):
                    ans = i+j+min(k,j)
            else:
                if ans > max(k,j):
                    ans = max(k,j)
        elif tt < b:
            if sorted([s[ss], x, t[tt]]).index(x) == 1:
                if ans > i+j+min(k,l):
                    ans = i+j+min(k,l)
            else:
                if ans > max(k,l):
                    ans = max(k,l)
    print(ans)



Fixed submission:
from bisect import bisect
a,b,q = map(int, input().split())
s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]

inf = float('INF')
for _ in range(q):
    x = int(input())
    # print('x', x)
    ss = bisect(s, x)
    tt = bisect(t, x)
    ans = inf
    for i in range(max(ss-1,0),min(ss+1,a)):
        for j in range(max(tt-1,0),min(tt+1,b)):
            ii,jj = abs(s[i] - x) + abs(s[i] - t[j]), abs(t[j] - x) + abs(s[i] - t[j])
            tmp = min(ii,jj)
            if ans > tmp:
                ans = tmp
    print(ans)