CodeEff/ECCO huggingface dataset:
# Original solution
#coding:utf-8
import bisect,math
import multiprocessing
A,B,Q=list(map(int,input().split()))
s=[0]*A
t=[0]*B
for i in range(A):
    s[i]=eval(input())
for i in range(B):
    t[i]=eval(input())
buf=[]
def f(x):
    sl=bisect.bisect_left(s,x)-1
    sr=sl+1
    tl=bisect.bisect_left(t,x)-1
    tr=tl+1
    ans=float("inf")
    if sl!=-1 and tl!=-1:
        A=max(s[sl],t[tl])
        B=min(s[sl],t[tl])
        L=abs(x-A)+abs(A-B)
        ans=min(ans,L)
    if sl!=-1 and tr!=len(t):
        L=abs(x-s[sl])*2 + abs(t[tr]-x)        
        ans=min(ans,L)
        ans=min(ans,abs(x-s[sl])+abs(t[tr]-x)*2)
    if tl!=-1 and sr!=len(s):
        ans=min(ans,abs(x-t[tl])*2+abs(s[sr]-x))
        ans=min(ans,abs(x-t[tl])+abs(s[sr]-x)*2)
    if tr!=len(t) and sr!=len(s):
        A=min(s[sr],t[tr])
        B=max(s[sr],t[tr])
        L=abs(A-x)+abs(B-A)
        ans=min(ans,L)
    return str(ans)

I=[0]*Q
for i in range(Q):
    I[i]=eval(input())
r=list(map(f,I))
print(("\n".join(r)))
    
    




# Optimized solution
#coding:utf-8
import bisect,sys
A,B,Q=list(map(int,input().split()))
s=[0]*A
t=[0]*B
for i in range(A):    
    s[i]=int(sys.stdin.readline())
for i in range(B):
    t[i]=int(sys.stdin.readline())
buf=[]
def f(x):
    sl=bisect.bisect_left(s,x)-1
    sr=sl+1
    tl=bisect.bisect_left(t,x)-1
    tr=tl+1
    ans=float("inf")
    if sl!=-1 and tl!=-1:
        A=max(s[sl],t[tl])
        B=min(s[sl],t[tl])
        L=abs(x-A)+abs(A-B)
        ans=min(ans,L)
    if sl!=-1 and tr!=len(t):
        L=abs(x-s[sl])*2 + abs(t[tr]-x)        
        ans=min(ans,L)
        ans=min(ans,abs(x-s[sl])+abs(t[tr]-x)*2)
    if tl!=-1 and sr!=len(s):
        ans=min(ans,abs(x-t[tl])*2+abs(s[sr]-x))
        ans=min(ans,abs(x-t[tl])+abs(s[sr]-x)*2)
    if tr!=len(t) and sr!=len(s):
        A=min(s[sr],t[tr])
        B=max(s[sr],t[tr])
        L=abs(A-x)+abs(B-A)
        ans=min(ans,L)
    return str(ans)

I=[0]*Q
for i in range(Q):
    I[i]=int(sys.stdin.readline())
r=list(map(f,I))
print(("\n".join(r)))
# Original solution
import bisect
import sys

A, B, Q = list(map(int,input().split()))
s = [-(10**18)] + list(map(int, (sys.stdin.readline() for _ in [0]*A))) + [10**18]
t = [-(10**18)] + list(map(int, (sys.stdin.readline() for _ in [0]*B))) + [10**18]


def solve(s,t,x):
    ans = 10**18
    for i in range(2):
        a, b = (s, t) if i==0 else (t, s)
        posX1 = bisect.bisect_left(a,x)
        for j in range(2):
            ax = a[posX1 -j]
            posX2 = bisect.bisect_left(b,ax)
            for k in range(2):
                bx = b[posX2-k]
                ans = min(ans, abs(x-ax)+abs(bx-ax))
    return ans

for _ in range(Q):
    x = int(eval(input()))
    print((solve(s,t,x)))

# Optimized solution
import bisect
import sys

A, B, Q = list(map(int,input().split()))
s = tuple([-(10**18)] + list(map(int, (sys.stdin.readline() for _ in [0]*A))) + [10**18])
t = tuple([-(10**18)] + list(map(int, (sys.stdin.readline() for _ in [0]*B))) + [10**18])


def solve(s,t,x):
    ans = 10**18
    for i in range(2):
        a, b = (s, t) if i==0 else (t, s)
        posX1 = bisect.bisect_left(a,x)
        for j in range(2):
            ax = a[posX1 -j]
            posX2 = bisect.bisect_left(b,ax)
            for k in range(2):
                bx = b[posX2-k]
                ans = min(ans, abs(x-ax)+abs(bx-ax))
    return ans

for _ in range(Q):
    x = int(eval(input()))
    print((solve(s,t,x)))
# Original solution
import bisect
import sys

A, B, Q = list(map(int,input().split()))
s = tuple([-(10**18)] + list(map(int, (sys.stdin.readline() for _ in [0]*A))) + [10**18])
t = tuple([-(10**18)] + list(map(int, (sys.stdin.readline() for _ in [0]*B))) + [10**18])


def solve(s,t,x):
    ans = 10**18
    for i in range(2):
        a, b = (s, t) if i==0 else (t, s)
        posX1 = bisect.bisect_left(a,x)
        for j in range(2):
            ax = a[posX1 -j]
            posX2 = bisect.bisect_left(b,ax)
            for k in range(2):
                bx = b[posX2-k]
                ans = min(ans, abs(x-ax)+abs(bx-ax))
    return ans

for _ in range(Q):
    x = int(eval(input()))
    print((solve(s,t,x)))

# Optimized solution
import bisect
import sys

A, B, Q = map(int,input().split())
s = tuple([-(10**18)] + list(map(int, (sys.stdin.readline() for _ in [0]*A))) + [10**18])
t = tuple([-(10**18)] + list(map(int, (sys.stdin.readline() for _ in [0]*B))) + [10**18])


def solve(s,t,x):
    ans = 10**18
    for i in range(2):
        a, b = (s, t) if i==0 else (t, s)
        posX1 = bisect.bisect_left(a,x)
        for j in range(2):
            ax = a[posX1 -j]
            posX2 = bisect.bisect_left(b,ax)
            for k in range(2):
                bx = b[posX2-k]
                ans = min(ans, abs(x-ax)+abs(bx-ax))
    return ans

ans = [solve(s,t,x) for x in map(int,sys.stdin)]
print(*ans, sep="\n")
# Original solution
from bisect import bisect_right
A, B, Q = list(map(int, input().split()))
BIG = 10**10 + 1
S = [-BIG] + [int(eval(input())) for _ in range(A)] + [BIG*2]
T = [-BIG] + [int(eval(input())) for _ in range(B)] + [BIG*2]
for _ in range(Q):
  x = int(eval(input()))
  shrine_b = bisect_right(S, x)
  dsl = x-S[shrine_b-1]
  dsr = S[shrine_b]-x
  temple_b = bisect_right(T, x)
  dtl = x-T[temple_b-1]
  dtr = T[temple_b]-x

  print((min(
    dsl if dsl > dtl else dtl,
    dsr if dsr > dtr else dtr,
    dsl * 2 + dtr,
    dsl + dtr * 2,
    dsr * 2 + dtl,
    dsr + dtl * 2
  )))

# Optimized solution
from bisect import bisect_left
A, B, Q = list(map(int, input().split()))
BIG = 10**10 + 1
S = [-BIG] + sorted([int(eval(input())) for _ in range(A)]) + [BIG*2]
T = [-BIG] + sorted([int(eval(input())) for _ in range(B)]) + [BIG*2]
for _ in range(Q):
  x = int(eval(input()))
  shrine_b = bisect_left(S, x)
  shrine_l = S[shrine_b-1]
  shrine_r = S[shrine_b]
  temple_b = bisect_left(T, x)
  temple_l = T[temple_b-1]
  temple_r = T[temple_b]
  print((min(
    x-shrine_l if shrine_l < temple_l else x-temple_l,
    shrine_r-x if shrine_r > temple_r else temple_r-x,
    (x-shrine_l) * 2 + temple_r-x,
    x-shrine_l + (temple_r-x) * 2,
    (shrine_r-x) * 2 + x-temple_l,
    shrine_r-x + (x-temple_l) * 2
  )))
# 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)]

for x in X:
    s_min = A-1
    for i in range(A):
        if s[i] > x:
            s_min = i-1
            break
    t_min = B-1
    for i in range(B):
        if t[i] > x:
            t_min = i-1
            break

    if s_min == -1:
        if t_min == -1:
            print((max(s[0]-x, t[0]-x)))
        elif t_min == B-1:
            print((s[0]-t[t_min]+min(s[0]-x, t[t_min]-x)))
        else:
            print((min(t[t_min+1]-x, s[0]-t[t_min]+min(s[0]-x, t[t_min]-x))))
    elif s_min == A-1:
        if t_min == -1:
            print((t[0]-s[s_min] + min(t[0]-x, x-s[s_min])))
        elif t_min == B-1:
            print((max(x-s[s_min], x-t[t_min])))
        else:
            print((min(x-t[t_min], t[t_min+1]-s[s_min] + min(t[t_min+1]-x, x-s[s_min]))))
    else:
        if t_min == -1:
            if t[0] < s[s_min+1]:
                print((min(s[s_min + 1] - x, t[0] - s[s_min] + min(t[0] - x, x-s[s_min]))))
            else:
                print((t[0]-x))
        elif t_min == B-1:
            print((min(x - s[s_min], s[s_min + 1] - t[t_min] + min(s[s_min + 1] - x, x - t[t_min]))))
        else:
            if s[s_min] < t[t_min]:
                if s[s_min+1] < t[t_min+1]:
                    print((min(x-s[s_min], t[t_min+1] - x, s[s_min+1] - t[t_min] + min(x-t[t_min], s[s_min+1]-x))))
                else:
                    print((min(x-s[s_min], s[s_min+1]-x)))
            else:
                if s[s_min+1] < t[t_min+1]:
                    print((min(t[t_min+1]-x, x-t[t_min])))
                else:
                    print((min(x-t[t_min], s[s_min+1] - x, t[t_min+1] - s[s_min] + min(x-s[s_min], t[t_min+1]-x))))




# 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]
X = [int(eval(input())) for i in range(Q)]


for x in X:
    s_min = bisect.bisect_left(s, x)
    t_min = bisect.bisect_left(t, x)

    cost = INF
    for S in [s[s_min-1], s[s_min]]:
        for T in [t[t_min-1], t[t_min]]:
            cost = min(cost, abs(T-S)+abs(T-x), abs(T-S)+abs(S-x))

    print(cost)
# Original solution
# coding: utf-8
# Your code here!
A,B,Q=list(map(int,input().split()))

def bisearch(target,lis):
    low=0
    high=len(lis)-1
    if lis[0]>target:
        return low-1
    elif lis[-1]<target:
        return high
    
    while lis[low]>target or lis[low+1]<target:
        mid=(low+high)//2
        if lis[mid]<target:
            high=mid
        else:
            low=mid
    return low

def cand(num,lis):
    N=len(lis)-1
    a=max(num,0)
    b=min(num+1,N)
    return [lis[a],lis[b]]

god=[]
for _ in range(A):
    god.append(int(eval(input())))

buddha=[]
for _ in range(B):
    buddha.append(int(eval(input())))

for _ in range(Q):
    q=int(eval(input()))
    g_i=(bisearch(q,god))
    b_i=(bisearch(q,buddha))
    G=cand(g_i,god)
    B=cand(b_i,buddha)
    ans=10**18
    ans=min(abs(q-G[0])+abs(G[0]-B[0]),abs(q-B[0])+abs(B[0]-G[0]),abs(q-G[1])+abs(G[1]-B[0]),abs(q-B[0])+abs(B[0]-G[1]),abs(q-G[0])+abs(G[0]-B[1]),abs(q-B[1])+abs(B[1]-G[0]),abs(q-G[1])+abs(G[1]-B[1]),abs(q-B[1])+abs(B[1]-G[1]))
    for g in G:
        for b in B:
            ans=min(ans,abs(q-g)+abs(g-b),abs(q-b)+abs(b-g))
    print(ans)


# Optimized solution
# coding: utf-8
# Your code here!
import bisect

A,B,Q=list(map(int,input().split()))

god=[-10**18]
for _ in range(A):
    god.append(int(eval(input())))
god.append(10**18)

buddha=[-10**18]
for _ in range(B):
    buddha.append(int(eval(input())))
buddha.append(10**18)

#print(god,buddha)
for _ in range(Q):
    q=int(eval(input()))
    g_i=bisect.bisect_left(god, q)
    b_i=bisect.bisect_left(buddha, q)
    #print(g_i,b_i)
    
    ans=10**18
    G=[god[g_i-1],god[g_i]]
    B=[buddha[b_i-1],buddha[b_i]]
    for g in G:
        for b in B:
            ans=min(ans,abs(q-g)+abs(g-b),abs(q-b)+abs(b-g))
    print(ans)
# Original solution
A, B, Q = [int(_) for _ in input().split()]
S = [int(eval(input())) for i in range(A)]
T = [int(eval(input())) for i in range(B)]
Q = [int(eval(input())) for i in range(Q)]

#print(S, T, Q)

def calc_m(xs):
    return [(a + b) / 2 for a, b in zip(xs, xs[1:])]

sm = calc_m(S)
tm = calc_m(T)

#print(sm)
#print(tm)

import bisect

def calc_nearest_0(xs, y, ym):
    result = []
    i = 0
    for x in xs:
        while i < len(ym) and x >= ym[i]:
            i += 1
        result.append(y[i])
    return result

def calc_nearest(xs, y, ym):
    result = []
    for x in xs:
        i = bisect.bisect(ym, x)
        result.append(y[i])
    return result

sn = calc_nearest(S, T, tm)
tn = calc_nearest(T, S, sm)

#print(sn)
#print(tn)

def solve(q, S, T, sn, tn):
    nsp = bisect.bisect(S, q)
    ntp = bisect.bisect(T, q)

    rs = []

    if 0 <= nsp < len(S):
        rs.append(abs(S[nsp] - q) + abs(S[nsp] - sn[nsp]))
    nsp -= 1
    if 0 <= nsp < len(S):
        rs.append(abs(S[nsp] - q) + abs(S[nsp] - sn[nsp]))

    if 0 <= ntp < len(T):
        rs.append(abs(T[ntp] - q) + abs(T[ntp] - tn[ntp]))
    ntp -= 1
    if 0 <= ntp < len(T):
        rs.append(abs(T[ntp] - q) + abs(T[ntp] - tn[ntp]))

    # print("Q", q, S, T, sn, tn, r1, r2)
    return min(rs)

for q in Q:
    print((solve(q, S, T, sn, tn)))


# Optimized solution
A, B, Q = [int(_) for _ in input().split()]
S = [int(eval(input())) for i in range(A)]
T = [int(eval(input())) for i in range(B)]
Q = [int(eval(input())) for i in range(Q)]

import bisect

def calc_nearest_distance(xs, ys):
    result = []
    for x in xs:
        i = bisect.bisect(ys, x)
        if i == 0:
            d = abs(ys[i] - x)
        elif i < len(ys):
            d = min(abs(ys[i - 1] - x), abs(ys[i] - x))
        else:
            d = abs(ys[i - 1] - x)
        result.append(d)
    return result

sn = calc_nearest_distance(S, T)
tn = calc_nearest_distance(T, S)

def solve(q, S, T, sn, tn):
    nsp = bisect.bisect(S, q)
    ntp = bisect.bisect(T, q)

    rs = []

    if 0 <= nsp < len(S):
        rs.append(abs(S[nsp] - q) + sn[nsp])
    if 0 <= nsp - 1 < len(S):
        rs.append(abs(S[nsp - 1] - q) + sn[nsp - 1])

    if 0 <= ntp < len(T):
        rs.append(abs(T[ntp] - q) + tn[ntp])
    if 0 <= ntp - 1 < len(T):
        rs.append(abs(T[ntp - 1] - q) + tn[ntp - 1])

    return min(rs)

for q in Q:
    print((solve(q, S, T, sn, tn)))
# Original solution
import bisect
import itertools
import sys

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)]


def most_simRL(ds, x):
    index = bisect.bisect_left(ds, x)
    if index == 0:
        return [ds[0]]
    elif index == len(ds):
        return [ds[-1]]
    return ds[index-1:index+1]


def calc(a, b, x):
    return min(abs(a-x), abs(b-x)) + abs(a-b)


for i in range(len(x)):
    s_RL = most_simRL(s, x[i])
    t_RL = most_simRL(t, x[i])
    ans = sys.maxsize
    for st in itertools.product(s_RL, t_RL):
        distance = calc(st[0], st[1], x[i])
        if ans > distance:
            ans = distance
    print(ans)


# Optimized solution
import bisect
import itertools
import sys

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)]


def most_simRL(ds, x):
    index = bisect.bisect_left(ds, x)
    if index == 0:
        return [ds[0]]
    elif index == len(ds):
        return [ds[-1]]
    return ds[index-1:index+1]


def calc(a, b, x):
    return min(abs(a-x), abs(b-x)) + abs(a-b)


for x in X:
    s_RL = most_simRL(s, x)
    t_RL = most_simRL(t, x)
    ans = sys.maxsize
    for st in itertools.product(s_RL, t_RL):
        ans = min(ans, calc(st[0], st[1], x))
    print(ans)
# Original solution
import bisect
import itertools
import sys

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)]


def most_simRL(ds, x):
    index = bisect.bisect_left(ds, x)
    if index == 0:
        return [ds[0]]
    elif index == len(ds):
        return [ds[-1]]
    return ds[index-1:index+1]


def calc(a, b, x):
    return min(abs(a-x), abs(b-x)) + abs(a-b)


for x in X:
    s_RL = most_simRL(s, x)
    t_RL = most_simRL(t, x)
    ans = sys.maxsize
    for st in itertools.product(s_RL, t_RL):
        ans = min(ans, calc(st[0], st[1], x))
    print(ans)


# Optimized solution
import bisect
import itertools
import sys

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)]


def most_simRL(ds, x):
    index = bisect.bisect_left(ds, x)
    if index == 0:
        return [ds[0]]
    elif index == len(ds):
        return [ds[-1]]
    return ds[index-1:index+1]


for x in X:
    s_RL = most_simRL(s, x)
    t_RL = most_simRL(t, x)
    ans = sys.maxsize
    for a, b in itertools.product(s_RL, t_RL):
        ans = min(ans, min(abs(a-x), abs(b-x)) + abs(a-b))
    print(ans)
# Original solution
from bisect import bisect_left
from itertools import product

a, b, q = [int(i) for i in input().split()]

s_list = [int(eval(input())) for _ in range(a)]
t_list = [int(eval(input())) for _ in range(b)]

n_list = [a, b]
s_t_list = [s_list, t_list]

for _ in range(q):
    x = int(eval(input()))

    temp_s_t_list = [[10 ** 11] * 2, [10 ** 11] * 2]
    for i in range(2):
        xi = bisect_left(s_t_list[i], x)

        if xi < n_list[i]:
            temp_s_t_list[i][0] = s_t_list[i][xi] - x
        if xi > 0:
            temp_s_t_list[i][1] = s_t_list[i][xi - 1] - x
    
    temp_list = []
    for s_x, t_x in list(product(temp_s_t_list[0], temp_s_t_list[1])):
        temp_s_x = s_x
        s_x = abs(s_x)
        temp_t_x = t_x
        t_x = abs(t_x)
        if temp_s_x // s_x == temp_t_x // t_x:
            temp_list.append(max(s_x, t_x))
        else:
            temp_list.append(s_x + t_x + min(s_x, t_x))
    print((min(temp_list)))

# Optimized solution
from bisect import bisect_left

a, b, q = [int(i) for i in input().split()]

s_list = [int(eval(input())) for _ in range(a)]
t_list = [int(eval(input())) for _ in range(b)]

for _ in range(q):
    x = int(eval(input()))

    temp_s_t_list = [10 ** 11] * 4
    
    si = bisect_left(s_list, x)
    if si < a:
        temp_s_t_list[0] = s_list[si] - x
    if si > 0:
        temp_s_t_list[1] = s_list[si - 1] - x
    
    ti = bisect_left(t_list, x)
    if ti < b:
        temp_s_t_list[2] = t_list[ti] - x
    if ti > 0:
        temp_s_t_list[3] = t_list[ti - 1] - x

    ans = 10 ** 11 * 3
    for s_x, t_x in [(temp_s_t_list[0], temp_s_t_list[2]), (temp_s_t_list[0], temp_s_t_list[3]), (temp_s_t_list[1], temp_s_t_list[2]), (temp_s_t_list[1], temp_s_t_list[3])]:
        temp_s_x = s_x
        s_x = abs(s_x)
        temp_t_x = t_x
        t_x = abs(t_x)
        if temp_s_x // s_x == temp_t_x // t_x:
            temp = max(s_x, t_x)
        else:
            temp = s_x + t_x + min(s_x, t_x)

        if ans > temp:
            ans = temp
    print(ans)
# Original solution
import bisect
A, B, Q = list(map(int, input().split()))
INF = float('inf')
s = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
t = [-INF] + [int(eval(input())) for _ 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)
    


# Optimized solution
from bisect import bisect_right
A, B, Q = list(map(int, input().split()))
INF = float('inf')
S = [-INF] + list(int(eval(input())) for _ in range(A)) + [INF]
T = [-INF] + list(int(eval(input())) for _ in range(B)) + [INF]
for _ in range(Q):
    x = int(eval(input()))
    i = bisect_right(S,x)
    j = bisect_right(T,x)
    d = INF
    for s in [S[i-1], S[i]]:
        for t in [T[j-1], T[j]]:
            d1 = abs(s-x) + abs(s-t)
            d2 = abs(t-x) + abs(s-t)
            d = min(d, d1, d2)
    print(d)
# Original solution
import bisect
A, B, Q = [int(_) for _ in 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)]
for x in X:
    i_sl = bisect.bisect_left(S, x)
    i_tl = bisect.bisect_left(T, x)
    D_sr = D_sl = D_tl = D_tr = float('inf')
    if i_sl < A:
        D_sl = S[i_sl] - x
    if i_tl < B:
        D_tl = T[i_tl] - x
    if i_sl:
        D_sr = x - S[i_sl - 1]
    if i_tl:
        D_tr = x - T[i_tl - 1]
    print((
        min([
            max(D_sl, D_tl),
            max(D_sr, D_tr),
            min(D_sl, D_tr) + D_tr + D_sl,
            min(D_tl, D_sr) + D_sr + D_tl
        ])))


# Optimized solution
import bisect
INF = float('inf')
A, B, Q = [int(_) for _ in input().split()]
S = [-INF] + [int(eval(input())) for _ in range(A)] + [INF]
T = [-INF] + [int(eval(input())) for _ in range(B)] + [INF]
X = [int(eval(input())) for _ in range(Q)]
for x in X:
    i_sl = bisect.bisect_left(S, x)
    i_tl = bisect.bisect_left(T, x)
    D_sl = S[i_sl] - x
    D_tl = T[i_tl] - x
    D_sr = x - S[i_sl - 1]
    D_tr = x - T[i_tl - 1]
    print((
        min([
            max(D_sl, D_tl),
            max(D_sr, D_tr),
            min(D_sl, D_tr) + D_tr + D_sl,
            min(D_tl, D_sr) + D_sr + D_tl
        ])))
# Original solution
a,b,q = list(map(int,input().split()))
s = [int(eval(input())) for i in range(0,a)]
t = [int(eval(input())) for i in range(0,b)]
x = [int(eval(input())) for i in range(0,q)]

s.sort()
t.sort()

def bifind(r,z):
    y = len(r)//2
    halftime = 2
    if z < r[0]:
        return [r[0],r[0]]
    elif z > r[-1]:
        return [r[-1],r[-1]]
    while True:
        if r[y] <= z:
            y += len(r)//(2**halftime)+1
        else:
            y -= len(r)//(2**halftime)+1
        halftime += 1
        if y+1  >= len(r):
            y = len(r)-2
        if y  < 0:
            y = 0
        if r[y] < z < r[y+1]:
            break
    return [r[y],r[y+1]]

for i in range(0,q):
    ls = bifind(s,x[i])
    lt = bifind(t,x[i])
    ans = list()
    for j in range(0,2):
        for k in range(0,2):
            ans.append(abs(ls[j]-x[i])+abs(lt[k]-ls[j]))
            ans.append(abs(lt[k]-x[i])+abs(lt[k]-ls[j]))
    print((min(ans)))

# Optimized solution
a,b,q = list(map(int,input().split()))
s = [int(eval(input())) for i in range(0,a)]
t = [int(eval(input())) for i in range(0,b)]
x = [int(eval(input())) for i in range(0,q)]

s.sort()
t.sort()

def bifind(r,z):
    low = 0
    high = len(r)-1
    y = (low + high)//2
    if z < r[0]:
        return [r[0],r[0]]
    elif z > r[-1]:
        return [r[-1],r[-1]]
    while True:
        if r[y] <= z:
            low = y
            y = (y+high)//2
        else:
            high = y
            y = (low + y)//2
        if r[y] < z < r[y+1]:
            break
    return [r[y],r[y+1]]

for i in range(0,q):
    ls = bifind(s,x[i])
    lt = bifind(t,x[i])
    ans = list()
    for j in range(0,2):
        for k in range(0,2):
            ans.append(abs(ls[j]-x[i])+abs(lt[k]-ls[j]))
            ans.append(abs(lt[k]-x[i])+abs(lt[k]-ls[j]))
    print((min(ans)))
# Original 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)]
X=[int(eval(input())) for _ in range(Q)]

import bisect
def solve(x):
    sr=bisect.bisect_right(S,x)
    tr=bisect.bisect_right(T,x)
    sl=sr-1
    tl=tr-1
    ret=10**12
    if sl>=0 and tl>=0:
        ret=min(ret,x-min(S[sl],T[tl]))
    if sr<A and tl>=0:
        ret=min(ret,S[sr]-T[tl]+min(S[sr]-x,x-T[tl]))
    if sl>=0 and tr<B:
        ret=min(ret,T[tr]-S[sl]+min(T[tr]-x,x-S[sl]))
    if sr<A and tr<B:
        ret=min(ret,max(S[sr],T[tr])-x)
    return ret

for x in X:
    print((solve(x)))

# Optimized solution
import sys
input = sys.stdin.readline
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)]

import bisect
def solve(x):
    sr=bisect.bisect_right(S,x)
    tr=bisect.bisect_right(T,x)
    sl=sr-1
    tl=tr-1
    ret=10**12
    if sl>=0 and tl>=0:
        ret=min(ret,x-min(S[sl],T[tl]))
    if sr<A and tl>=0:
        ret=min(ret,S[sr]-T[tl]+min(S[sr]-x,x-T[tl]))
    if sl>=0 and tr<B:
        ret=min(ret,T[tr]-S[sl]+min(T[tr]-x,x-S[sl]))
    if sr<A and tr<B:
        ret=min(ret,max(S[sr],T[tr])-x)
    return ret

for x in X:
    print((solve(x)))