CodeEff/ECCO huggingface dataset:
# Original solution
import bisect,sys
input = sys.stdin.readline
a,b,q = list(map(int,input().split()))
INF = float('inf')
S = [-INF]+[int(eval(input())) for i in range(a)]+[INF]
T = [-INF]+[int(eval(input())) for i in range(b)]+[INF]

def f(S,T):
    res = INF
    s = bisect.bisect_left(S,x)
    for i in range(2):
    	for j in range(2):
            t = bisect.bisect_left(T,S[s-i])
            ans= abs(x-S[s-i])+abs(S[s-i]-T[t-j])
            if ans < res:
                res = ans
    return res

for i in range(q):
    x = int(eval(input()))
    print((min(f(S,T),f(T,S))))


# Optimized solution
from bisect import bisect_left
import sys
input = sys.stdin.readline
a,b,q = list(map(int,input().split()))
inf = float('inf')
S = [-inf]+[int(eval(input())) for i in range(a)]+[inf]
T = [-inf]+[int(eval(input())) for i in range(b)]+[inf]

def f(S,T):
    res = 10**30 
    s = bisect_left(S,x)

    ans = 0
    t = bisect_left(T,S[s-1])
    ans += abs(x-S[s-1])+min(abs(S[s-1]-T[t-1]),abs(S[s-1]-T[t]))
    if ans <= res:
        res = ans
    
    ans = 0
    t = bisect_left(T,S[s])
    ans += abs(x-S[s])+min(abs(S[s]-T[t-1]),abs(S[s]-T[t]))
    if ans <= res:
        res = ans

    return res


for i in range(q):
    x = int(eval(input()))
    print((min(f(S,T),f(T,S))))
# Original solution
A, B, Q = list(map(int, input().split()))
s = [int(eval(input())) for i in range(A)]
t = [int(eval(input())) for i in range(B)]
x = [int(eval(input())) for i in range(Q)]

def search(a):
  cur = a
  sx, tx = [], [] #xiとsi、tiの差のリスト
  for si in s:
    sx.append(abs(si - a))
  for ti in t:
    tx.append(abs(ti - a))
  stmin = [[sx.index(min(sx)),min(sx)], [tx.index(min(tx)),min(tx)]]
  ans = min(stmin[0][1], stmin[1][1])
  
#  if stmin[0][1] <= stmin[1][1]: #sのほうが近いとき
  cur1 = s[stmin[0][0]]
  tcur = []
  for ti in t:
    tcur.append(abs(ti - cur1))
  ans1 = stmin[0][1] + min(tcur)
    
#  if stmin[0][1] > stmin[1][1]: #tのほうが近いとき
  cur2 = t[stmin[1][0]]
  scur = []
  for si in s:
    scur.append(abs(si - cur2))
  ans2 = stmin[1][1] + min(scur)
  
  print((min(ans1, ans2)))
  
for xi in x:
  search(xi)

# Optimized solution
import bisect
A, B, Q = list(map(int, input().split()))
INF = 10 ** 18
s = [-INF] + [int(eval(input())) for i in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(B)] + [INF]
for q in range(Q):
  x = int(eval(input()))
  b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
  res = INF
  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)
# Original solution
import bisect


def solve(A, B, Q, Ss, Ts, Xs):
    ans = []
    Ss.append(10 ** 21)
    Ss.insert(0, -10 ** 21)
    Ts.append(10 ** 21)
    Ts.insert(0, -10 ** 21)
    for x in Xs:
        s_right = bisect.bisect_right(Ss, x)
        s_left = max(s_right - 1, 0)
        t_right = bisect.bisect_right(Ts, x)
        t_left = max(t_right - 1, 0)

        s_right = Ss[s_right]
        s_left = Ss[s_left]
        t_right = Ts[t_right]
        t_left = Ts[t_left]

        d_s_right = abs(s_right - x)
        d_s_left = abs(s_left - x)
        d_t_right = abs(t_right - x)
        d_t_left = abs(t_left - x)

        tans = 10 ** 35
        if x <= s_right and x <= t_right:
            tans = min(tans, max(d_t_right, d_s_right))
        if s_right <= x and t_right <= x:
            tans = min(tans, max(d_t_right, d_s_right))
        if s_left <= x and t_left <= x:
            tans = min(tans, max(d_s_left, d_t_left))
        tans = min(tans, min(d_s_right, d_t_left) * 2 + max(d_s_right, d_t_left))
        tans = min(tans, min(d_t_right, d_s_left) * 2 + max(d_t_right, d_s_left))
        ans.append(str(tans))
    return "\n".join(ans)

if __name__ == "__main__":
    A, B, Q = tuple(map(int, input().split(" ")))
    Ss = [int(eval(input())) for _ in range(A)]
    Ts = [int(eval(input())) for _ in range(B)]
    Xs = [int(eval(input())) for _ in range(Q)]
    print((solve(A, B, Q, Ss, Ts, Xs)))


# Optimized solution
import bisect


def solve(A, B, Q, Ss, Ts, Xs):
    ans = []
    Ss.append(10 ** 21)
    Ss.insert(0, -10 ** 21)
    Ts.append(10 ** 21)
    Ts.insert(0, -10 ** 21)
    for x in Xs:
        s_right = bisect.bisect_right(Ss, x)
        s_left = max(s_right - 1, 0)
        t_right = bisect.bisect_right(Ts, x)
        t_left = max(t_right - 1, 0)

        s_right = Ss[s_right]
        s_left = Ss[s_left]
        t_right = Ts[t_right]
        t_left = Ts[t_left]

        d_s_right = abs(s_right - x)
        d_s_left = abs(s_left - x)
        d_t_right = abs(t_right - x)
        d_t_left = abs(t_left - x)

        tans = 10 ** 35
        if x <= s_right and x <= t_right:
            tans = min(tans, max(d_t_right, d_s_right))
        if s_left <= x and t_left <= x:
            tans = min(tans, max(d_s_left, d_t_left))
        tans = min(tans, min(d_s_right, d_t_left) * 2 + max(d_s_right, d_t_left))
        tans = min(tans, min(d_t_right, d_s_left) * 2 + max(d_t_right, d_s_left))
        ans.append(str(tans))
    return "\n".join(ans)


if __name__ == "__main__":
    A, B, Q = tuple(map(int, input().split(" ")))
    Ss = [int(eval(input())) for _ in range(A)]
    Ts = [int(eval(input())) for _ in range(B)]
    Xs = [int(eval(input())) for _ in range(Q)]
    print((solve(A, B, Q, Ss, Ts, Xs)))
# Original solution
from bisect import bisect_right

def getINearests(ss, ts):
    iNearests = [-1] * len(ss)
    for iS, s in enumerate(ss):
        iT = bisect_right(ts, s)
        if iT == len(ts):
            iNearests[iS] = iT-1
        elif iT == 0:
            iNearests[iS] = 0
        else:
            d1 = abs(s - ts[iT-1])
            d2 = abs(s - ts[iT])
            if d1 <= d2:
                iNearests[iS] = iT-1
            else:
                iNearests[iS] = iT
    return iNearests


A, B, Q = list(map(int, input().split()))
ss = [int(eval(input())) for _ in range(A)]
ts = [int(eval(input())) for _ in range(B)]
xs = [int(eval(input())) for _ in range(Q)]

iTNearests = getINearests(ss, ts)
iSNearests = getINearests(ts, ss)

anss = [0] * Q
for iX, x in enumerate(xs):
    ans = float('inf')

    # 初手: 神社
    iS = bisect_right(ss, x)
    if iS > 0:
        cost = abs(x - ss[iS-1])
        cost += abs(ss[iS-1] - ts[iTNearests[iS-1]])
        ans = min(ans, cost)
    if iS < A:
        cost = abs(x - ss[iS])
        cost += abs(ss[iS] - ts[iTNearests[iS]])
        ans = min(ans, cost)

    # 初手: 寺
    iT = bisect_right(ts, x)
    if iT > 0:
        cost = abs(x - ts[iT-1])
        cost += abs(ts[iT-1] - ss[iSNearests[iT-1]])
        ans = min(ans, cost)
    if iT < B:
        cost = abs(x - ts[iT])
        cost += abs(ts[iT] - ss[iSNearests[iT]])
        ans = min(ans, cost)

    anss[iX] = ans

print(('\n'.join(map(str, anss))))


# Optimized solution
import sys
from bisect import bisect_right

def solve():
    def getINearests(ss, ts):
        iNearests = [-1] * len(ss)
        for iS, s in enumerate(ss):
            iT = bisect_right(ts, s)
            if iT == len(ts):
                iNearests[iS] = iT-1
            elif iT == 0:
                iNearests[iS] = 0
            else:
                d1 = abs(s - ts[iT-1])
                d2 = abs(s - ts[iT])
                if d1 <= d2:
                    iNearests[iS] = iT-1
                else:
                    iNearests[iS] = iT
        return iNearests


    A, B, Q = list(map(int, input().split()))
    ss = [int(sys.stdin.readline()) for _ in range(A)]
    ts = [int(sys.stdin.readline()) for _ in range(B)]
    xs = [int(sys.stdin.readline()) for _ in range(Q)]

    iTNearests = getINearests(ss, ts)
    iSNearests = getINearests(ts, ss)

    anss = [0] * Q
    for iX, x in enumerate(xs):
        ans = float('inf')

        # 初手: 神社
        iS = bisect_right(ss, x)
        if iS > 0:
            cost = abs(x - ss[iS-1])
            cost += abs(ss[iS-1] - ts[iTNearests[iS-1]])
            if cost < ans: ans = cost
        if iS < A:
            cost = abs(x - ss[iS])
            cost += abs(ss[iS] - ts[iTNearests[iS]])
            if cost < ans: ans = cost

        # 初手: 寺
        iT = bisect_right(ts, x)
        if iT > 0:
            cost = abs(x - ts[iT-1])
            cost += abs(ts[iT-1] - ss[iSNearests[iT-1]])
            if cost < ans: ans = cost
        if iT < B:
            cost = abs(x - ts[iT])
            cost += abs(ts[iT] - ss[iSNearests[iT]])
            if cost < ans: ans = cost

        anss[iX] = ans

    print(('\n'.join(map(str, anss))))

solve()
# Original solution
import bisect
a, b, q = list(map(int, input().split()))
INF = 10 ** 18
s = [-INF] + [int(eval(input())) for i in range(a)] + [INF]
t = [-INF] + [int(eval(input())) for i in range(b)] + [INF]
for question in range(q):
    x = int(eval(input()))
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for shrine in [s[b - 1], s[b]]:
        for temple in [t[d - 1], t[d]]:
            d1, d2 = abs(shrine - x) + abs(temple - shrine), abs(temple - x) + abs(shrine - temple)
            res = min(res, d1, d2)
    print(res)


# Optimized solution
from bisect import bisect_right as br
a,b,q=list(map(int,input().split()))
I=2<<60
s,t=[-I]+[int(eval(input())) for _ in range(a)]+[I],[-I]+[int(eval(input())) for _ in range(b)]+[I]
for question in range(q):
    x=int(eval(input()))
    b,d,r=br(s,x),br(t,x),I
    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)
            r=min(r,d1,d2)
    print(r)
# Original solution
import bisect


A, B, Q = list(map(int, input().split()))
s = [-10 ** 12] + [int(eval(input())) for _ in range(A)] + [10 ** 12]
t = [-10 ** 12] + [int(eval(input())) for _ in range(B)] + [10 ** 12]
x = [int(eval(input())) for _ in range(Q)]
for i in x:
    si = bisect.bisect_left(s, i)
    ti = bisect.bisect_left(t, i)
    s1, s2 = s[si - 1], s[si]
    t1, t2 = t[ti - 1], t[ti]
    ans = 10 ** 12
    for ss in [s1, s2]:
        for tt in [t1, t2]:
            ans = min(ans, abs(i - ss) + abs(ss - tt),
                      abs(i - tt) + abs(ss - tt))
    print(ans)

# Optimized solution
import bisect


A, B, Q = list(map(int, input().split()))
S = [int(eval(input())) for _ in range(A)]
T = [int(eval(input())) for _ in range(B)]
X = [int(eval(input())) for _ in range(Q)]
S = [-10 ** 12] + S + [10 ** 12]
T = [-10 ** 12] + T + [10 ** 12]
for x in X:
    si = bisect.bisect_right(S, x)
    ti = bisect.bisect_right(T, x)
    Ls, Rs = x - S[si - 1], -x + S[si]
    Lt, Rt = x - T[ti - 1], -x + T[ti]
    ans = min(Ls * 2 + Rt, Ls + Rt * 2, Lt * 2 + Rs,
              Lt + Rs * 2, max(Ls, Lt), max(Rs, Rt))
    print(ans)
# Original solution
A,B,Q=list(map(int,input().split()))
s=[0]*(A+2)
t=[0]*(B+2)
X=[0]*Q
s[0] = -float('inf')
s[A+1] = float('inf')
t[0] = -float('inf')
t[B+1] = float('inf')
for i in range(1,A+1):
    s[i] = int(eval(input()))
for i in range(1,B+1):
    t[i] = int(eval(input()))
for i in range(Q):
    X[i] = int(eval(input()))

import bisect


def dec(x,s,t):
    s_ = s-x
    t_ = t-x
    as_ = abs(s_)
    at_ = abs(t_)
    if (s_>0 and t_<0) or (s_<0 and t_>0):
        return as_ + at_ + min(as_, at_)
    else:
        return max(as_,at_)


for x in X:
    s_i = bisect.bisect_left(s,x)
    t_i = bisect.bisect_left(t,x)
    s_l = s[s_i-1]
    s_r = s[s_i]
    t_l = t[t_i-1]
    t_r = t[t_i]
    ans = dec(x,s_l,t_l)
    ans_ = dec(x,s_l,t_r)
    if ans > ans_:
        ans = ans_
    ans_ = dec(x,s_r,t_l)
    if ans > ans_:
        ans = ans_
    ans_ = dec(x,s_r,t_r)
    if ans > ans_:
        ans = ans_
    print(ans)




# Optimized solution
A,B,Q=list(map(int,input().split()))
s=[0]*(A+2)
t=[0]*(B+2)
X=[0]*Q
s[0] = -float('inf')
s[A+1] = float('inf')
t[0] = -float('inf')
t[B+1] = float('inf')
for i in range(1,A+1):
    s[i] = int(eval(input()))
for i in range(1,B+1):
    t[i] = int(eval(input()))
for i in range(Q):
    X[i] = int(eval(input()))

import bisect

for x in X:
    s_i = bisect.bisect_left(s,x)
    t_i = bisect.bisect_left(t,x)
    s_l = abs(s[s_i-1]-x)
    s_r = s[s_i]-x
    t_l = abs(t[t_i-1]-x)
    t_r = t[t_i]-x
    ans = min([max(s_l,t_l),s_l+t_r+min(s_l,t_r),s_r+t_l+min(s_r,t_l),max(s_r,t_r)])

    print(ans)
# Original solution
import bisect

A,B,Q=list(map(int,input().split()))
S=[-10**18]+[int(eval(input())) for _ in range(A)]+[10**18]
T=[-10**18]+[int(eval(input())) for _ in range(B)]+[10**18]

for i in range(Q):
    x=int(eval(input()))
    b,d=bisect.bisect_right(S,x), bisect.bisect_right(T,x)
    ans=float("inf")
    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)
            ans=min(ans,d1,d2)
    print(ans)

# Optimized solution
import bisect

INF=10**18
A,B,Q=list(map(int,input().split()))
S=[0]*(A+2)
T=[0]*(B+2)
S[0],T[0]=-INF,-INF
S[A+1],T[B+1]=INF,INF

for i in range(1,A+1):
    S[i]=int(eval(input()))

for i in range(1,B+1):
    T[i]=int(eval(input()))

for i in range(Q):
    x=int(eval(input()))
    b,d=bisect.bisect_right(S,x), bisect.bisect_right(T,x)
    ans=INF
    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)
            ans=min(ans,d1,d2)
    print(ans)
# Original solution
import bisect
import sys

a, b, q = list(map(int, input().split()))
lines = sys.stdin.readlines()
sss = list(map(int, lines[:a]))
ttt = list(map(int, lines[a:a + b]))
xxx = list(map(int, lines[a + b:]))

nearest_temples = [0] * a
nearest_shrines = [0] * b
for i, s in enumerate(sss):
    ti = bisect.bisect(ttt, s)
    nt = 10 ** 11
    if ti > 0:
        nt = min(nt, abs(s - ttt[ti - 1]))
    if ti < b:
        nt = min(nt, abs(s - ttt[ti]))
    nearest_temples[i] = nt
for i, t in enumerate(ttt):
    si = bisect.bisect(sss, t)
    ns = 10 ** 11
    if si > 0:
        ns = min(ns, abs(t - sss[si - 1]))
    if si < a:
        ns = min(ns, abs(t - sss[si]))
    nearest_shrines[i] = ns

buf = []
for x in xxx:
    si = bisect.bisect(sss, x)
    ti = bisect.bisect(ttt, x)
    ans = 10 ** 11
    if si > 0:
        ans = min(ans, x - sss[si - 1] + nearest_temples[si - 1])
    if si < a:
        ans = min(ans, sss[si] - x + nearest_temples[si])
    if ti > 0:
        ans = min(ans, x - ttt[ti - 1] + nearest_shrines[ti - 1])
    if ti < b:
        ans = min(ans, ttt[ti] - x + nearest_shrines[ti])
    buf.append(ans)
print(('\n'.join(map(str, buf))))


# Optimized solution
import bisect
import sys

SENTINEL = 10 ** 12

a, b, q = list(map(int, input().split()))
lines = sys.stdin.readlines()
sss = [-SENTINEL] + list(map(int, lines[:a])) + [SENTINEL]
ttt = [-SENTINEL] + list(map(int, lines[a:a + b])) + [SENTINEL]
xxx = list(map(int, lines[a + b:]))

nearest_temples = [SENTINEL] + [0] * a + [SENTINEL]
nearest_shrines = [SENTINEL] + [0] * b + [SENTINEL]
for i, s in enumerate(sss[1:-1], start=1):
    ti = bisect.bisect(ttt, s)
    nearest_temples[i] = min(ttt[ti] - s, s - ttt[ti - 1])
for i, t in enumerate(ttt[1:-1], start=1):
    si = bisect.bisect(sss, t)
    nearest_shrines[i] = min(sss[si] - t, t - sss[si - 1])

buf = []
for x in xxx:
    si = bisect.bisect(sss, x)
    ti = bisect.bisect(ttt, x)
    ans = min(x - sss[si - 1] + nearest_temples[si - 1],
              sss[si] - x + nearest_temples[si],
              x - ttt[ti - 1] + nearest_shrines[ti - 1],
              ttt[ti] - x + nearest_shrines[ti])
    buf.append(ans)
print(('\n'.join(map(str, buf))))
# Original solution
a, b, q = list(map(int, input().split()))
s = []
t = []
x = []
for i in range(a):
    s.append(int(eval(input())))
for i in range(b):
    t.append(int(eval(input())))
for i in range(q):
    x.append(int(eval(input())))
import bisect
def get(x):
    ls,rs,lt,rt=10**13,10**13,10**13,10**13
    s_ind = bisect.bisect_left(s,x)
    t_ind = bisect.bisect_left(t,x)
    if s_ind!=0:
        ls=abs(x - s[s_ind-1])
    if s_ind!=a:
        rs=abs(x - s[s_ind])
    if t_ind!=0:
        lt=abs(x - t[t_ind-1])
    if t_ind!=b:
        rt=abs(x - t[t_ind])
    return ls,rs,lt,rt

for que in x:
    ls,rs,lt,rt = get(que)

    rr = max(rs,rt)
    ll = max(ls,lt)
    lsrt = 2*ls+rt
    ltrs = 2*lt+rs
    rslt = 2*rs+lt
    rtls = 2*rt+ls
    ans = min([rr,ll,lsrt,ltrs,rslt,rtls])
    print(ans)

# Optimized solution
import sys
input=sys.stdin.readline
a, b, q = list(map(int, input().split()))
s = []
t = []
x = []
for i in range(a):
    s.append(int(eval(input())))
for i in range(b):
    t.append(int(eval(input())))
for i in range(q):
    x.append(int(eval(input())))
import bisect
def get(x):
    ls,rs,lt,rt=10**13,10**13,10**13,10**13
    s_ind = bisect.bisect_left(s,x)
    t_ind = bisect.bisect_left(t,x)
    if s_ind!=0:
        ls=abs(x - s[s_ind-1])
    if s_ind!=a:
        rs=abs(x - s[s_ind])
    if t_ind!=0:
        lt=abs(x - t[t_ind-1])
    if t_ind!=b:
        rt=abs(x - t[t_ind])
    return ls,rs,lt,rt

for que in x:
    ls,rs,lt,rt = get(que)

    rr = max(rs,rt)
    ll = max(ls,lt)
    lsrt = 2*ls+rt
    ltrs = 2*lt+rs
    rslt = 2*rs+lt
    rtls = 2*rt+ls
    ans = min([rr,ll,lsrt,ltrs,rslt,rtls])
    print(ans)
# Original solution
import sys
input = sys.stdin.readline
INF = 10**11
A,B,Q = list(map(int,input().split()))
s = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
def binary_search(lis,x):
    ok = 0
    ng = len(lis)-1
    while ng-ok > 1:
        mid = (ok+ng)//2
        if lis[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok
#print(s,t)
for _ in range(Q):
    x = int(eval(input()))
    ps = binary_search(s,x)
    pt = binary_search(t,x)
    ans = INF
    #print(ps,pt)
    for i in range(ps,ps+2):
        for j in range(pt,pt+2):
            ds = x - s[i]
            dt = x - t[j]
            
            if (ds < 0 and dt < 0) or (ds > 0 and dt > 0):
                ans = min(ans,max(abs(ds),abs(dt)))
            else:
                ans = min(ans,abs(ds)+abs(dt)+min(abs(ds),abs(dt)))
    print(ans)  
            


# Optimized solution
import sys
input = sys.stdin.readline
INF = 10**11
A,B,Q = list(map(int,input().split()))
s = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
def binary_search(lis,x):
    ok = 0
    ng = len(lis)-1
    while ng-ok > 1:
        mid = (ok+ng)//2
        if lis[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok
#print(s,t)
for _ in range(Q):
    x = int(eval(input()))
    ps = binary_search(s,x)
    pt = binary_search(t,x)
    ans = INF
    #print(ps,pt)
    for i in range(ps,ps+2):
        for j in range(pt,pt+2):
            ans = min(ans,abs(s[i]-x)+abs(s[i]-t[j]), abs(t[j]-x)+abs(t[j]-s[i]))
    print(ans)
# Original solution
a,b,q=list(map(int,input().split()))
s=sorted([int(eval(input())) for _ in range(a)])
t=sorted([int(eval(input())) for _ in range(b)])
import bisect
for _ in range(q):
    x=int(eval(input()))
    ss=[x-s[max(bisect.bisect_left(s,x)-1,0)],x-s[min(bisect.bisect_right(s,x),a-1)]]
    tt=[x-t[max(bisect.bisect_left(t,x)-1,0)],x-t[min(bisect.bisect_right(t,x),b-1)]]
    l=[]
    for i in ss:
        for j in tt:
            if i*j>=0:
                l.append(max(abs(i),abs(j)))
            else:
                l.append(max(abs(i),abs(j))+2*min(abs(i),abs(j)))
    print((min(l)))


# Optimized solution
a,b,q=list(map(int,input().split()))
s=[int(eval(input())) for _ in range(a)]
t=[int(eval(input())) for _ in range(b)]
import bisect
for _ in range(q):
    x=int(eval(input()))
    sb=bisect.bisect_left(s,x)
    tb=bisect.bisect_left(t,x)
    ss=[x-s[max(sb-1,0)],x-s[min(sb,a-1)]]
    tt=[x-t[max(tb-1,0)],x-t[min(tb,b-1)]]
    l=[]
    for i in ss:
        for j in tt:
            if i*j>=0:
                l.append(max(abs(i),abs(j)))
            else:
                l.append(max(abs(i),abs(j))+2*min(abs(i),abs(j)))
    print((min(l)))
# Original solution
def near(x, Y):
    i = bisect_left(Y,x)
    if i == 0:
        return Y[i]-x
    elif i == len(Y):
        return x-Y[i-1]
    else:
        return min(Y[i]-x, x-Y[i-1])

def near2(x, D):
    Y = [d for d ,_ in D]
    i = bisect_left(Y,x)
    if i == 0:
        return Y[i]-x + D[i][1]
    elif i == len(Y):
        return x-Y[i-1] + D[i-1][1]
    else:
        return min(Y[i]-x+D[i][1], x-Y[i-1]+D[i-1][1])

from bisect import *
A, B, Q = list(map(int, input().split()))
S = []
T = []
for _ in range(A):
    S.append(int(eval(input())))
for _ in range(B):
    T.append(int(eval(input())))
D = []
for a in S:
    D.append((a, near(a, T)))
for b in T:
    D.append((b, near(b, S)))
D.sort(key=lambda x:x[0])
for _ in range(Q):
    x = int(eval(input()))
    print((near2(x,D)))



# Optimized solution
def near(x, Y):
    i = bisect_left(Y,x)
    if i == 0:
        return Y[i]-x
    elif i == len(Y):
        return x-Y[i-1]
    else:
        return min(Y[i]-x, x-Y[i-1])

def near2(x, Y):
    i = bisect_left(Y,x)
    if i == 0:
        return Y[i]-x + D[i][1]
    elif i == len(Y):
        return x-Y[i-1] + D[i-1][1]
    else:
        return min(Y[i]-x+D[i][1], x-Y[i-1]+D[i-1][1])

from bisect import *
A, B, Q = list(map(int, input().split()))
S = []
T = []
for _ in range(A):
    S.append(int(eval(input())))
for _ in range(B):
    T.append(int(eval(input())))
D = []
for a in S:
    D.append((a, near(a, T)))
for b in T:
    D.append((b, near(b, S)))
D.sort(key=lambda x:x[0])
D2 = [d for d, _ in D]
for _ in range(Q):
    x = int(eval(input()))
    print((near2(x,D2)))
# Original solution
def near(x, Y):
    i = bisect_left(Y,x)
    if i == 0:
        return Y[i]-x
    elif i == len(Y):
        return x-Y[i-1]
    else:
        return min(Y[i]-x, x-Y[i-1])

def near2(x, Y):
    i = bisect_left(Y,x)
    if i == 0:
        return Y[i]-x + D[i][1]
    elif i == len(Y):
        return x-Y[i-1] + D[i-1][1]
    else:
        return min(Y[i]-x+D[i][1], x-Y[i-1]+D[i-1][1])

from bisect import *
A, B, Q = list(map(int, input().split()))
S = []
T = []
for _ in range(A):
    S.append(int(eval(input())))
for _ in range(B):
    T.append(int(eval(input())))
D = []
for a in S:
    D.append((a, near(a, T)))
for b in T:
    D.append((b, near(b, S)))
D.sort(key=lambda x:x[0])
D2 = [d for d, _ in D]
for _ in range(Q):
    x = int(eval(input()))
    print((near2(x,D2)))



# Optimized solution
def near(x, X):
    i = bisect_left(X, x)
    if i == 0: return [X[i]-x]
    elif i == len(X): return [X[i-1]-x]
    else: return [X[i]-x, X[i-1]-x]
from bisect import *
A, B, Q = list(map(int, input().split()))
S, T = [], []
for _ in range(A):
    S.append(int(eval(input())))
for _ in range(B):
    T.append(int(eval(input())))
for _ in range(Q):
    res = 1<<40
    x = int(eval(input()))
    for a in near(x,S):
        for b in near(x,T):
            res = min(abs(a)+abs(a-b), abs(b)+abs(b-a), res)
    print(res)
# Original solution
def near(x, X):
    i = bisect_left(X, x)
    if i == 0: return [X[i]-x]
    elif i == len(X): return [X[i-1]-x]
    else: return [X[i]-x, X[i-1]-x]
from bisect import *
from itertools import product
A, B, Q = list(map(int, input().split()))
S, T = [], []
for _ in range(A):
    S.append(int(eval(input())))
for _ in range(B):
    T.append(int(eval(input())))
for _ in range(Q):
    res = 1<<40
    x = int(eval(input()))
    for a, b in product(near(x,S), near(x,T)):
            res = min(abs(a)+abs(a-b), abs(b)+abs(b-a), res)
    print(res)

# Optimized solution
def near(x, X):
    i = bisect_left(X, x)
    if i == 0: return [X[i]-x]
    elif i == len(X): return [X[i-1]-x]
    else: return [X[i]-x, X[i-1]-x]
import sys
input = sys.stdin.readline
from bisect import *
from itertools import product
A, B, Q = list(map(int, input().split()))
S, T = [], []
for _ in range(A):
    S.append(int(eval(input())))
for _ in range(B):
    T.append(int(eval(input())))
for _ in range(Q):
    res = 1<<40
    x = int(eval(input()))
    for a, b in product(near(x,S), near(x,T)):
            res = min(abs(a)+abs(a-b), abs(b)+abs(b-a), res)
    print(res)