Buggy python submission (verdict: Time Limit Exceeded):
A,B,q = map(int,input().split())
import bisect
L1=[]
L2=[]
for _ in range(A):
    L1.append(int(input()))
for _ in range(B):
    L2.append(int(input()))
L1 = [-10**20] + L1 + [10**20]
L2 = [-10**20] + L2 + [10**20]
for _ in range(q):
    Q = int(input())
    cand = []
    for i in range(2):
        for j in range(2):
                t =  L1[bisect.bisect_left(L1,Q)-i]
                tmp = abs (t - Q)
                tmp  +=  abs(L2[bisect.bisect_left(L2,t)-j]  - t)
                cand.append(tmp)
                t =  L2[bisect.bisect_left(L2,Q)-i]
                tmp = abs (t - Q)
                tmp  +=  abs(L1[bisect.bisect_left(L1,t)-j]  - t)
                cand.append(tmp)
    print(min(cand))



Fixed submission:
A,B,Q = map(int,input().split())
import bisect
s=[]
t=[]
for _ in range(A):
    s.append(int(input()))
for _ in range(B):
    t.append(int(input()))
s = [-10**20] + s + [10**20]
t = [-10**20] + t + [10**20]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = 10**20
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), 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())
import bisect
L1=[]
L2=[]
for _ in range(A):
    L1.append(int(input()))
for _ in range(B):
    L2.append(int(input()))
L1 = [-10**20] + L1 + [10**20]
L2 = [-10**20] + L2 + [10**20]
for _ in range(q):
    Q = int(input())
    cand = []
    for i in range(2):
        for j in range(2):
                t =  L1[bisect.bisect_left(L1,Q)-i]
                tmp = abs (t - Q)
                tmp  +=  abs(L2[bisect.bisect_left(L2,t)-j]  - t)
                cand.append(tmp)
                t =  L2[bisect.bisect_left(L2,Q)-i]
                tmp = abs (t - Q)
                tmp  +=  abs(L1[bisect.bisect_left(L1,t)-j]  - t)
                cand.append(tmp)
    print(min(cand))



Fixed submission:
A,B,Q = map(int,input().split())
import bisect
s=[]
t=[]
for _ in range(A):
    s.append(int(input()))
for _ in range(B):
    t.append(int(input()))
s = [-10**20] + s + [10**20]
t = [-10**20] + t + [10**20]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = 10**20
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), 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())
import bisect
L1=[]
L2=[]
for _ in range(A):
    L1.append(int(input()))
for _ in range(B):
    L2.append(int(input()))
L1 = [-10**9] + L1 + [10**9]
L2 = [-10**9] + L2 + [10**9]
for _ in range(q):
    Q = int(input())
    cand = []
    for i in range(2):
        for j in range(2):
                t =  L1[bisect.bisect_left(L1,Q)-i]
                tmp = abs (t - Q)
                tmp  +=  abs(L2[bisect.bisect_left(L2,t)-j]  - t)
                cand.append(tmp)
                t =  L2[bisect.bisect_left(L2,Q)-i]
                tmp = abs (t - Q)
                tmp  +=  abs(L1[bisect.bisect_left(L1,t)-j]  - t)
                cand.append(tmp)
    print(min(cand))



Fixed submission:
A,B,Q = map(int,input().split())
import bisect
s=[]
t=[]
for _ in range(A):
    s.append(int(input()))
for _ in range(B):
    t.append(int(input()))
s = [-10**20] + s + [10**20]
t = [-10**20] + t + [10**20]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = 10**20
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), 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())
import bisect
L1=[]
L2=[]
for _ in range(A):
    L1.append(int(input()))
for _ in range(B):
    L2.append(int(input()))
for _ in range(q):
    Q = int(input())
    cand = []
    for i in range(2):
        for j in range(2):
            try:
                t =  L1[bisect.bisect_left(L1,Q)-i]
                tmp = abs (t - Q)
                tmp  +=  abs(L2[bisect.bisect_left(L2,t)-j]  - t)
                cand.append(tmp)
            except:
                pass
            try:
                t =  L2[bisect.bisect_left(L2,Q)-i]
                tmp = abs (t - Q)
                tmp  +=  abs(L1[bisect.bisect_left(L1,t)-j]  - t)
                cand.append(tmp)
            except:
                pass
    print(min(cand))


Fixed submission:
A,B,Q = map(int,input().split())
import bisect
s=[]
t=[]
for _ in range(A):
    s.append(int(input()))
for _ in range(B):
    t.append(int(input()))
s = [-10**20] + s + [10**20]
t = [-10**20] + t + [10**20]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = 10**20
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), 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())
import bisect
L1=[]
L2=[]
for _ in range(A):
    L1.append(int(input()))
for _ in range(B):
    L2.append(int(input()))
for _ in range(q):
    Q = int(input())
    cand = []
    for i in range(2):
        for j in range(2):
            try:
                t =  L1[bisect.bisect_left(L1,Q)-i]
                tmp = abs (t - Q)
                tmp  +=  abs(L2[bisect.bisect_left(L2,t)-j]  - t)
                cand.append(tmp)
            except:
                pass
            try:
                t =  L2[bisect.bisect_left(L2,Q)-i]
                tmp = abs (t - Q)
                tmp  +=  abs(L1[bisect.bisect_left(L1,t)-j]  - t)
                cand.append(tmp)
            except:
                pass
    print(min(cand))


Fixed submission:
A,B,Q = map(int,input().split())
import bisect
s=[]
t=[]
for _ in range(A):
    s.append(int(input()))
for _ in range(B):
    t.append(int(input()))
s = [-10**20] + s + [10**20]
t = [-10**20] + t + [10**20]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = 10**20
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)