CodeEff/ECCO huggingface dataset:
# Original solution
from bisect import bisect_left as bl
A, B, Q = list(map(int, input().split()))
inf = 10 ** 11
Sh = [-1 * inf] + [int(eval(input())) for _ in range(A)] + [inf]
Te = [-1 * inf] + [int(eval(input())) for _ in range(B)] + [inf]
for _ in range(Q):
  q = int(eval(input()))
  temp = inf
  i = bl(Sh, q)
  que = []
  que.append(i)
  if i != 0:
    que.append(i - 1)
  while len(que):
    j = que.pop()
    k = bl(Te, Sh[j])
    temp = min(temp, abs(Sh[j] - Te[k]) + abs(Sh[j] - q))
    if k != 0:
      temp = min(temp, abs(Sh[j] - Te[k - 1]) + abs(Sh[j] - q))
  i = bl(Te, q)
  if abs(Te[i] - q) < temp:
    que.append(i)
  if abs(Te[i - 1] - q) < temp:
    que.append(i)
    if i != 0:
      que.append(i - 1)
  while len(que):
    j = que.pop()
    k = bl(Sh, Te[j])
    temp = min(temp, abs(Te[j] - Sh[k]) + abs(Te[j] - q))
    if k != 0:
      temp = min(temp, abs(Te[j] - Sh[k - 1]) + abs(Te[j] - q))
  print(temp)

# Optimized solution
from bisect import bisect_left as bl
A, B, Q = list(map(int, input().split()))
inf = 10 ** 11
Sh = [-1 * inf] + [int(eval(input())) for _ in range(A)] + [inf]
Te = [-1 * inf] + [int(eval(input())) for _ in range(B)] + [inf]
for _ in range(Q):
  x = int(eval(input()))
  b, d = bl(Sh, x), bl(Te, x)
  res = inf
  for S in [Sh[b - 1], Sh[b]]:
    for T in [Te[d - 1], Te[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 sys
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: list(map(int, readline().split()))
in_s = lambda: readline().rstrip().decode('utf-8')

INF = 10**12
d = lambda a, b: abs(a - b)


def main():

    A, B, Q = in_nn()
    tmp = list(map(int, read().split()))
    s = tmp[:A]
    t = tmp[A:A + B]
    x = tmp[A + B:]

    a = [0] * Q

    for i in range(Q):

        n = x[i]

        if n <= s[0]:
            a1 = -INF
            a2 = s[0]
        elif n >= s[-1]:
            a1 = s[-1]
            a2 = INF
        else:
            si = bisect.bisect_right(s, n)
            a1 = s[si - 1]
            a2 = s[si]

        if n <= t[0]:
            b1 = -INF
            b2 = t[0]
        elif n >= t[-1]:
            b1 = t[-1]
            b2 = INF
        else:
            ti = bisect.bisect_right(t, n)
            b1 = t[ti - 1]
            b2 = t[ti]

        # print(a1, a2, b1, b2)
        ans = d(n, a1) + min(d(a1, b1), d(a1, b2))
        ans = min(ans, d(n, a2) + min(d(a2, b1), d(a2, b2)))
        ans = min(ans, d(n, b1) + min(d(b1, a1), d(b1, a2)))
        ans = min(ans, d(n, b2) + min(d(b2, a1), d(b2, a2)))
        a[i] = ans

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


if __name__ == '__main__':
    main()


# Optimized solution
import sys
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: list(map(int, readline().split()))
in_s = lambda: readline().rstrip().decode('utf-8')

INF = 10**12


def main():

    A, B, Q = in_nn()
    tmp = list(map(int, read().split()))
    s = [-INF] + tmp[:A] + [INF]
    t = [-INF] + tmp[A:A + B] + [INF]
    x = tmp[A + B:]

    a = [0] * Q
    d = lambda a, b: abs(a - b)

    for i in range(Q):

        n = x[i]

        si = bisect.bisect_right(s, n)
        a1 = s[si - 1]
        a2 = s[si]

        ti = bisect.bisect_right(t, n)
        b1 = t[ti - 1]
        b2 = t[ti]

        ans = d(n, a1) + min(d(a1, b1), d(a1, b2))
        ans = min(ans, d(n, a2) + min(d(a2, b1), d(a2, b2)))
        ans = min(ans, d(n, b1) + min(d(b1, a1), d(b1, a2)))
        ans = min(ans, d(n, b2) + min(d(b2, a1), d(b2, a2)))
        a[i] = ans

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


if __name__ == '__main__':
    main()
# Original solution
import bisect

f_inf = float('inf')


def cal(syurui, d, index):
    if d == 'e':
        return syurui[index]
    elif d == 'w':
        return syurui[index - 1]


A, B, Q = list(map(int, input().split()))
s = [int(eval(input())) for i in range(A)]
s.sort()
t = [int(eval(input())) for i in range(B)]
t.sort()
ｓ.insert(0, -f_inf)
t.insert(0, -f_inf)
ｓ.append(f_inf)
t.append(f_inf)

for i in range(Q):
    x = int(eval(input()))
    s_index = bisect.bisect_left(s, x)
    t_index = bisect.bisect_left(t, x)
    print((min(max(abs(x-s[s_index]), abs(x-t[t_index])), max(abs(x-s[s_index-1]), abs(x-t[t_index-1])), 2*abs(x-s[s_index-1])+abs(x-t[t_index]), 2*abs(x-s[s_index])+abs(x-t[t_index-1]), abs(x-s[s_index-1])+2*abs(x-t[t_index]), abs(x-s[s_index])+2*abs(x-t[t_index-1]))))


# Optimized solution
import bisect
import sys

f_inf = float('inf')


def cal(syurui, d, index):
    if d == 'e':
        return syurui[index]
    elif d == 'w':
        return syurui[index - 1]


A, B, Q = list(map(int, input().split()))
s = [int(eval(input())) for i in range(A)]
s.sort()
t = [int(eval(input())) for i in range(B)]
t.sort()
ｓ.insert(0, -f_inf)
t.insert(0, -f_inf)
ｓ.append(f_inf)
t.append(f_inf)

for i in range(Q):
    x = int(sys.stdin.readline().rstrip('\n'))
    s_index = bisect.bisect_left(s, x)
    t_index = bisect.bisect_left(t, x)
    print((min(max(abs(x - s[s_index]), abs(x - t[t_index])), max(abs(x - s[s_index - 1]), abs(x - t[t_index - 1])), 2 * abs(x - s[s_index - 1]) + abs(x - t[t_index]),
              2 * abs(x - s[s_index]) + abs(x - t[t_index - 1]), abs(x - s[s_index - 1]) + 2 * abs(x - t[t_index]), abs(x - s[s_index]) + 2 * abs(x - t[t_index - 1]))))
# Original solution
from bisect import bisect_left

INF = 2 * 10**10

A, B, Q = map(int, input().split())
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]
ans = []
for x in X:
    sr = bisect_left(S, x) 
    sl = sr -1
    if sr != len(S) and S[sr] == x:
        sl = sr
    tr = bisect_left(T, x)
    tl = tr - 1
    if tr != len(T) and T[tr] == x:
        tl = tr

    ll = INF if sl == -1 or tl == -1 else x - min(S[sl], T[tl])
    rr = INF if sr == len(S) or tr == len(T) else max(S[sr], T[tr]) - x
    lsrt = INF if sl == -1 or tr == len(T) else 2*(x-S[sl]) + (T[tr] - x)
    ltrs = INF if tl == -1 or sr == len(S) else 2*(x-T[tl]) + (S[sr] - x)
    rslt = INF if tl == -1 or sr == len(S) else 2*(S[sr] - x) + (x - T[tl])
    rtls = INF if sl == -1 or tr == len(T) else 2*(T[tr] - x) + (x - S[sl])

    ans.append(min(ll, rr, lsrt, ltrs, rslt, rtls))
print(*ans, sep='\n')


# Optimized solution
from bisect import bisect_left

INF = 2 * 10**10

A, B, Q = map(int, input().split())
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]
X = [int(input()) for _ in range(Q)]
ans = []
for x in X:
    sr = bisect_left(S, x) 
    sl = sr if S[sr] == x else sr -1
    tr = bisect_left(T, x)
    tl = tr if T[tr] == x else tr -1

    ll = x - min(S[sl], T[tl])
    rr = max(S[sr], T[tr]) - x
    lsrt = 2*(x-S[sl]) + (T[tr] - x)
    ltrs = 2*(x-T[tl]) + (S[sr] - x)
    rslt = 2*(S[sr] - x) + (x - T[tl])
    rtls = 2*(T[tr] - x) + (x - S[sl])

    ans.append(min(ll, rr, lsrt, ltrs, rslt, rtls))
print(*ans, sep='\n')
# Original solution
from bisect import bisect_left
def main():
  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)]
  inf=10**11
  minf=-10**11
  s=[minf]+s+[inf]
  t=[minf]+t+[inf]
  for i in range(q):
    ns=bisect_left(s,x[i])
    nt=bisect_left(t,x[i])
    ans=float('inf')
    for j in [s[ns],s[ns-1]]:
      for k in [t[nt],t[nt-1]]:
        ans=min(ans,min(abs(x[i]-j),abs(x[i]-k))+abs(max(j,k)-min(j,k)))
    print(ans)
if __name__=='__main__':
  main()

# Optimized solution
from bisect import bisect_left
import sys
def main():
  input=sys.stdin.readline
  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)]
  inf=10**11
  minf=-10**11
  s=[minf]+s+[inf]
  t=[minf]+t+[inf]
  for i in range(q):
    ns=bisect_left(s,x[i])
    nt=bisect_left(t,x[i])
    ans=float('inf')
    for j in [s[ns],s[ns-1]]:
      for k in [t[nt],t[nt-1]]:
        ans=min(ans,min(abs(x[i]-j),abs(x[i]-k))+abs(max(j,k)-min(j,k)))
    print(ans)
if __name__=='__main__':
  main()
# Original solution
import sys
input = sys.stdin.readline

import bisect

INF = 1e+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]
x = [int(eval(input())) for _ in range(Q)]

for i in range(Q):
    a,b= bisect.bisect_right(s,x[i]), bisect.bisect_right(t,x[i])
    ans = INF
    for S in [s[a-1], s[a]]:
        for T in [t[b-1], t[b]]:
            d1 = abs(S-x[i])+abs(S-T)
            d2 = abs(T-x[i])+abs(S-T)
            ans = min(ans, d1, d2)
    print(ans)



# Optimized solution
import sys
input = sys.stdin.readline

import bisect

INF = 1e+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]
x=[int(eval(input())) for _ in range(Q)]

for i in range(Q):
    a,b=bisect.bisect_right(s,x[i]), bisect.bisect_right(t,x[i])
    ans = INF
    for j in [s[a-1], s[a]]:
        for k in [t[b-1], t[b]]:
            d1 = abs(j-x[i])+abs(j-k)
            d2 = abs(k-x[i])+abs(j-k)
            ans = min(ans, d1, d2)
    print(ans)
# Original 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)]

for i in range(q):
    x = int(eval(input()))
    xs = bisect.bisect(s,x)
    xt = bisect.bisect(t,x)
   
    ds = []
    if 0 < xs < a:
        ds.append([s[xs-1],abs(x-s[xs-1])])
        ds.append([s[xs],abs(x-s[xs])])
    elif xs == a:
        ds.append([s[xs-1],abs(x-s[xs-1])])
    else:
        ds.append([s[xs],abs(x-s[xs])])
    
    dt = []
    if 0 < xt < b:
        dt.append([t[xt-1],abs(x-t[xt-1])])
        dt.append([t[xt],abs(x-t[xt])])
    elif xt == b:
        dt.append([t[xt-1],abs(x-t[xt-1])])
    else:
        dt.append([t[xt],abs(x-t[xt])])

    ans = []
    for j in range(len(ds)):
        for k in range(len(dt)):
            ans.append(ds[j][1] + abs(dt[k][0]-ds[j][0]))
            
    for j in range(len(dt)):
        for k in range(len(ds)):
            ans.append(dt[j][1] + abs(ds[k][0]-dt[j][0]))
    print((min(ans)))

# Optimized solution
import bisect
a,b,q = list(map(int,input().split()))
s = [-float('inf')] + [int(eval(input())) for _ in range(a)] + [float('inf')]
t = [-float('inf')] + [int(eval(input())) for _ in range(b)] + [float('inf')]

for i in range(q):
    x = int(eval(input()))
    xs = bisect.bisect(s,x)
    xt = bisect.bisect(t,x)
    S = [s[xs-1],s[xs]]
    T = [t[xt-1],t[xt]]
    
    ans = float('inf')
    for j in range(2):
        for k in range(2):
            ans = min(ans, abs(S[j]-x) + abs(S[j]-T[k]))
            ans = min(ans, abs(T[j]-x) + abs(T[j]-S[k]))
    print(ans)
# Original solution
A, B, Q = list(map(int, input().split()))
# もし神社(寺)が1つしかなかった場合に両端に仮想の神社を建築して処理の一貫性を保つ。かりにこれが選ばれても最大のコストなので最終的に最適になることはない。
INF = 10 ** 18

S = [-INF] + [int(eval(input())) for _ in range(A)]+[INF]
T = [-INF] + [int(eval(input())) for _ in range(B)]+[INF]

from bisect import bisect_left as bisect_right
from itertools import product


for q in range(Q):  # 各問に答える
    x = int(eval(input()))  # 位置の指定
    s_idx, t_idx = bisect_right(S, x), bisect_right(T, x)
    ans = INF
    # 左右の神社と寺のの組み合わせ
    for s, t in product(S[s_idx - 1:s_idx + 1], T[t_idx - 1:t_idx + 1]):
        t_root = abs(t - x) + abs(s - t)  # 寺から最初に回るルート
        s_root = abs(s - x) + abs(s - t)
        ans = min(ans, t_root, s_root)
    # 最小をとって終わり
    print(ans)

'''
bisect_right

ソートされた順序を保ったまま x を a に挿入できる点を探し当てます。リストの中から検索する部分集合を指定するには、パラメータの lo と hi を使います。デフォルトでは、リスト全体が使われます。x がすでに a に含まれている場合、挿入点は既存のどのエントリーよりも後(右)になります。戻り値は、list.insert() の第一引数として使うのに適しています。a はすでにソートされているものとします。


In[3]: A
Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In[4]: bisect.bisect_right(A, 2.5)
Out[4]: 3

In[5]: bisect.bisect_right(A, 3)
Out[5]: 4
'''


# Optimized solution
from sys import stdin
A, B, Q = list(map(int, input().split()))
# もし神社(寺)が1つしかなかった場合に両端に仮想の神社を建築して処理の一貫性を保つ。かりにこれが選ばれても最大のコストなので最終的に最適になることはない。
INF = 10 ** 18

S = [-INF] + [int(stdin.readline()) for _ in range(A)]+[INF]
T = [-INF] + [int(stdin.readline()) for _ in range(B)]+[INF]

from bisect import bisect_right
# from bisect import bisect_left as bisect_right #これでも通ったりする。
from itertools import product

for q in range(Q):  # 各問に答える
    x = int(eval(input()))  # 位置の指定
    s_idx, t_idx = bisect_right(S, x), bisect_right(T, x)
    ans = INF
    # 左右の神社と寺のの組み合わせ
    for s, t in product(S[s_idx - 1:s_idx + 1], T[t_idx - 1:t_idx + 1]):
        t_root = abs(t - x) + abs(s - t)  # 寺から最初に回るルート
        s_root = abs(s - x) + abs(s - t)
        ans = min(ans, t_root, s_root)
    # 最小をとって終わり
    print(ans)

'''
bisect_right

ソートされた順序を保ったまま x を a に挿入できる点を探し当てます。リストの中から検索する部分集合を指定するには、パラメータの lo と hi を使います。デフォルトでは、リスト全体が使われます。x がすでに a に含まれている場合、挿入点は既存のどのエントリーよりも後(右)になります。戻り値は、list.insert() の第一引数として使うのに適しています。a はすでにソートされているものとします。


In[3]: A
Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In[4]: bisect.bisect_right(A, 2.5)
Out[4]: 3

In[5]: bisect.bisect_right(A, 3)
Out[5]: 4
'''
# Original solution
from sys import stdin
A, B, Q = list(map(int, input().split()))
# もし神社(寺)が1つしかなかった場合に両端に仮想の神社を建築して処理の一貫性を保つ。かりにこれが選ばれても最大のコストなので最終的に最適になることはない。
INF = 10 ** 18

S = [-INF] + [int(stdin.readline()) for _ in range(A)]+[INF]
T = [-INF] + [int(stdin.readline()) for _ in range(B)]+[INF]

from bisect import bisect_right
# from bisect import bisect_left as bisect_right #これでも通ったりする。
from itertools import product

for q in range(Q):  # 各問に答える
    x = int(eval(input()))  # 位置の指定
    s_idx, t_idx = bisect_right(S, x), bisect_right(T, x)
    ans = INF
    # 左右の神社と寺のの組み合わせ
    for s, t in product(S[s_idx - 1:s_idx + 1], T[t_idx - 1:t_idx + 1]):
        t_root = abs(t - x) + abs(s - t)  # 寺から最初に回るルート
        s_root = abs(s - x) + abs(s - t)
        ans = min(ans, t_root, s_root)
    # 最小をとって終わり
    print(ans)

'''
bisect_right

ソートされた順序を保ったまま x を a に挿入できる点を探し当てます。リストの中から検索する部分集合を指定するには、パラメータの lo と hi を使います。デフォルトでは、リスト全体が使われます。x がすでに a に含まれている場合、挿入点は既存のどのエントリーよりも後(右)になります。戻り値は、list.insert() の第一引数として使うのに適しています。a はすでにソートされているものとします。


In[3]: A
Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In[4]: bisect.bisect_right(A, 2.5)
Out[4]: 3

In[5]: bisect.bisect_right(A, 3)
Out[5]: 4
'''


# Optimized solution
from sys import stdin
A, B, Q = list(map(int, input().split()))
# もし神社(寺)が1つしかなかった場合に両端に仮想の神社を建築して処理の一貫性を保つ。かりにこれが選ばれても最大のコストなので最終的に最適になることはない。
INF = 10 ** 18

S = [-INF] + list(map(int, (stdin.readline() for _ in range(A))))+[INF]
T = [-INF] + list(map(int, (stdin.readline() for _ in range(B))))+[INF]

from bisect import bisect_right
# from bisect import bisect_left as bisect_right #これでも通ったりする。
from itertools import product

for q in range(Q):  # 各問に答える
    x = int(eval(input()))  # 位置の指定
    s_idx, t_idx = bisect_right(S, x), bisect_right(T, x)
    ans = INF
    # 左右の神社と寺のの組み合わせ
    for s, t in product(S[s_idx - 1:s_idx + 1], T[t_idx - 1:t_idx + 1]):
        t_root = abs(t - x) + abs(s - t)  # 寺から最初に回るルート
        s_root = abs(s - x) + abs(s - t)
        ans = min(ans, t_root, s_root)
    # 最小をとって終わり
    print(ans)

'''
bisect_right

ソートされた順序を保ったまま x を a に挿入できる点を探し当てます。リストの中から検索する部分集合を指定するには、パラメータの lo と hi を使います。デフォルトでは、リスト全体が使われます。x がすでに a に含まれている場合、挿入点は既存のどのエントリーよりも後(右)になります。戻り値は、list.insert() の第一引数として使うのに適しています。a はすでにソートされているものとします。


In[3]: A
Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In[4]: bisect.bisect_right(A, 2.5)
Out[4]: 3

In[5]: bisect.bisect_right(A, 3)
Out[5]: 4
'''
# Original solution
# from sys import stdin #入力の高速化(0.2秒ぐらい早くなる)
A, B, Q = list(map(int, input().split()))
# もし神社(寺)が1つしかなかった場合に両端に仮想の神社を建築して処理の一貫性を保つ。かりにこれが選ばれても最大のコストなので最終的に最適になることはない。
INF = 10 ** 18

# S = [-INF] + list(map(int, (stdin.readline() for _ in [0] * A))) + [INF]
# T = [-INF] + list(map(int, [stdin.readline() for _ in [0] * B])) + [INF]
S = [-INF] + [int(eval(input())) for _ in range(A)]+[INF]
T = [-INF] + [int(eval(input())) for _ in range(B)]+[INF]

from bisect import bisect_right
# from bisect import bisect_left as bisect_right #これでも通ったりする。
from itertools import product

for q in range(Q):  # 各問に答える
    x = int(eval(input()))  # 位置の指定
    s_idx, t_idx = bisect_right(S, x), bisect_right(T, x)
    ans = INF
    # 左右の神社と寺のの組み合わせ
    for s, t in product(S[s_idx - 1:s_idx + 1], T[t_idx - 1:t_idx + 1]):
        t_root = abs(t - x) + abs(s - t)  # 寺から最初に回るルート
        s_root = abs(s - x) + abs(s - t)
        ans = min(ans, t_root, s_root)
    # 最小をとって終わり
    print(ans)

'''
bisect_right

ソートされた順序を保ったまま x を a に挿入できる点を探し当てます。リストの中から検索する部分集合を指定するには、パラメータの lo と hi を使います。デフォルトでは、リスト全体が使われます。x がすでに a に含まれている場合、挿入点は既存のどのエントリーよりも後(右)になります。戻り値は、list.insert() の第一引数として使うのに適しています。a はすでにソートされているものとします。


In[3]: A
Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In[4]: bisect.bisect_right(A, 2.5)
Out[4]: 3

In[5]: bisect.bisect_right(A, 3)
Out[5]: 4
'''


# 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
A,B,Q = list(map(int,input().split()))
Ss = []
for i in range(A):
    Ss.append(int(eval(input())))
Ts = []
for i in range(B):
    Ts.append(int(eval(input())))

def binary_search(search_list,target):
    left = 0
    right = len(search_list)
    while left < right:
        center = (left + right)//2
        if search_list[center] < target:
            left = center + 1
        elif search_list[center] > target:
            right = center
    index = left
    return index-1

S_to_T = []
for i in range(A):
    index = binary_search(Ts,Ss[i])
    if index+1 == B:
        right = float('inf')
    else:
        right = abs(Ss[i]-Ts[index+1])
    length = min(abs(Ss[i]-Ts[index]),right)
    S_to_T.append(length)
T_to_S = []
for i in range(B):
    index = binary_search(Ss,Ts[i])
    if index+1 == A:
        right = float('inf')
    else:
        right = abs(Ts[i]-Ss[index+1])
    length = min(abs(Ts[i]-Ss[index]),right)
    T_to_S.append(length)

for i in range(Q):
    q = int(eval(input()))
    Sindex = binary_search(Ss,q)
    S_left = abs(Ss[Sindex]-q)+S_to_T[Sindex]
    if Sindex+1 == A:
        S_right = float('inf')
    else:
        S_right = abs(Ss[Sindex+1]-q)+S_to_T[Sindex+1]
    Tindex = binary_search(Ts,q)
    T_left = abs(Ts[Tindex]-q)+T_to_S[Tindex]
    if Tindex+1 == B:
        T_right = float('inf')
    else:
        T_right = abs(Ts[Tindex+1]-q)+T_to_S[Tindex+1]
    ans = min(S_left,S_right,T_left,T_right)
    print(ans)

# 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
a, b, q = list(map(int, input().split()))
S = [int(eval(input())) for _ in range(a)]
T = [int(eval(input())) for _ in range(b)]
S.sort()
T.sort()
INF = 10**18
S = [-INF] + S + [INF]
T = [-INF] + T + [INF]

import bisect
for _ in range(q):
    x = int(eval(input()))
    i = bisect.bisect_right(S, x)
    j = bisect.bisect_right(T, x)
    ans = INF
    for s in [S[i-1], S[i]]:
        for t in [T[j-1], T[j]]:
            d1 = abs(s-x) + abs(t-s)
            d2 = abs(t-x) + abs(s-t)
            ans = min([ans, d1, d2])
    print(ans)

# Optimized solution
import sys
input = sys.stdin.buffer.readline

a, b, q = list(map(int, input().split()))
S = [0]*a
T = [0]*b
for i in range(a):
    s = int(eval(input()))
    S[i] = s
for i in range(b):
    t = int(eval(input()))
    T[i] = t

S.sort()
T.sort()
S = [-10**18]+S+[10**18]
T = [-10**18]+T+[10**18]
import bisect
for i in range(q):
    x = int(eval(input()))
    ans = 10**18
    ids = bisect.bisect_right(S, x)
    idt = bisect.bisect_right(T, x)
    for ks in (-1, 0):
        for kt in (-1, 0):
            s = S[ids+ks]
            t = T[idt+kt]
            temp = min(abs(s-x)+abs(s-t), abs(t-x)+abs(s-t))
            ans = min(ans, temp)
    print(ans)
# Original solution
import bisect
from functools import reduce

A, B, Q = list(map(int,input().split()))
INF = float("inf")
s = [-1*INF]
t = [-1*INF]
for _ in range(A):
    s.append(int(eval(input())))
s.append(INF)
for _ in range(B):
    t.append(int(eval(input())))
t.append(INF)
for _ in range(Q):
    x = int(eval(input()))
    s_index = bisect.bisect_left(s,x)
    t_index = bisect.bisect_left(t,x)
    s_l = x - s[s_index-1]
    s_r = s[s_index] - x
    t_l = x - t[t_index-1]
    t_r = t[t_index] - x
    ans = reduce(min, [max(s_l,t_l), s_l + t_r*2, s_r + t_l*2, s_l*2 + t_r, s_r*2 + t_l, max(s_r,t_r)])
    print(ans)

# Optimized solution
from bisect import bisect_left
A, B, Q = list(map(int,input().split()))
INF = 2 * 10 ** 10
S = [-INF]
T = [-INF]
for _ in range(A):
    S.append(int(eval(input())))
S.append(INF)
for _ in range(B):
    T.append(int(eval(input())))
T.append(INF)
for _ in range(Q):
    x = int(eval(input()))
    s = bisect_left(S, x)
    t = bisect_left(T, x)
    ans = min(max(S[s], T[t]) - x, x - min(S[s-1], T[t-1]), 2 * S[s] - T[t-1] - x, 2 * T[t] - S[s-1] - x, T[t] + x - 2 * S[s-1], S[s] + x - 2 * T[t-1])
    print(ans)
# Original solution
import sys
import bisect
a, b, q = [int(i) for i in sys.stdin.readline().split()]
s_ls = []
t_ls = []
INF = 10 ** 18
for i in range(a):
    s = int(eval(input()))
    s_ls.append(s)
for i in range(b):
    t = int(eval(input()))
    t_ls.append(t)

for i in range(q):
    x = int(eval(input()))
    s_ind = min(bisect.bisect_left(s_ls, x), a-1)
    t_ind = min(bisect.bisect_left(t_ls, x), b-1)
    best = INF
    for _s in [-1, 0]:
        if s_ind == 0 and _s == -1:
            continue
        for _t in [-1, 0]:
            if t_ind == 0 and _t == -1:
                continue
            s = s_ls[s_ind + _s]
            t = t_ls[t_ind + _t]
            if (s - x) * (t - x) >= 0:
                dis = max(abs(t - x), abs(s - x))
            else:
                dis = min(abs(t - x), abs(s - x)) * 2 + max(abs(t - x), abs(s - x))
            best = min(dis, best)
    print(best)

# Optimized solution
import sys
import bisect
_input = sys.stdin.readlines()
a, b, q = [int(i) for i in _input[0].split()]
data = [int(i) for i in _input[1:]]
s_ls = data[:a]
t_ls = data[a:a+b]
x_ls = data[-q:]
INF = 10 ** 18

for x in x_ls:
    s_ind = min(bisect.bisect_left(s_ls, x), a-1)
    t_ind = min(bisect.bisect_left(t_ls, x), b-1)
    best = INF
    for _s in [-1, 0]:
        if s_ind == 0 and _s == -1:
            continue
        for _t in [-1, 0]:
            if t_ind == 0 and _t == -1:
                continue
            s = s_ls[s_ind + _s]
            t = t_ls[t_ind + _t]
            if (s - x) * (t - x) >= 0:
                dis = max(abs(t - x), abs(s - x))
            else:
                dis = min(abs(t - x), abs(s - x)) * 2 + max(abs(t - x), abs(s - x))
            best = min(dis, best)
    print(best)