CodeEff/ECCO huggingface dataset:
# Original solution
import sys
def main():
    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)]
    from bisect import bisect_left
    INF=10**11
    S=[-INF] + S + [INF]
    T=[-INF] + T + [INF]
    for x in X:
        sr = bisect_left(S, x)
        tr = bisect_left(T, x)
        sl,tl=sr-1,tr-1
        ans=INF
        ans = min(ans, abs(S[sl]-T[tl]) + min(abs(S[sl]-x), abs(T[tl]-x)))
        ans = min(ans, abs(S[sl]-T[tr]) + min(abs(S[sl]-x), abs(T[tr]-x)))
        ans = min(ans, abs(S[sr]-T[tl]) + min(abs(S[sr]-x), abs(T[tl]-x)))
        ans = min(ans, abs(S[sr]-T[tr]) + min(abs(S[sr]-x), abs(T[tr]-x)))
        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 _ in range(A)]
    T = [int(eval(input())) for _ in range(B)]
    X = [int(eval(input())) for _ in range(Q)]
    INF = 10 ** 11
    S = [-INF] + S + [INF]
    T = [-INF] + T + [INF]
    for x in X:
        i = bisect_left(S, x)
        ls = x - S[i - 1]
        rs = S[i] - x
        j = bisect_left(T, x)
        lt = x - T[j - 1]
        rt = T[j] - x
        print((min(max(ls, lt), max(rs, rt), 2 * ls + rt, ls + 2 * rt, 2 * rs + lt, rs + 2 * lt)))

if __name__ == '__main__':
    main()
# Original solution
from bisect import bisect_left
a,b,q,*stx = list(map(int,open(0).read().split()))
s = [-1e10] + stx[:a] + [2*1e10]
t = [-1e10] + stx[a:-q] + [2*1e10]
x = stx[-q:]
for i in x:
    pos_s = bisect_left(s,i)
    pos_t = bisect_left(t,i)
    sl = s[pos_s-1]; sr = s[pos_s]
    tl = t[pos_t-1]; tr = t[pos_t]
    ans = min( i-min(sl,tl), max(sr,tr)-i, (sr*2-i-tl), (tr*2-i-sl), (i+tr-sl*2), (i+sr-tl*2) )
    print(ans)

# Optimized solution
from bisect import bisect

def main():
    a,b,q,*stx = list(map(int,open(0).read().split()))
    s = [-1e10] + stx[:a] + [2*1e10]
    t = [-1e10] + stx[a:a+b] + [2*1e10]
    x = stx[a+b:a+b+q]
    for i in x:
        pos_s = bisect(s,i)
        pos_t = bisect(t,i)
        sl = s[pos_s-1]; sr = s[pos_s]
        tl = t[pos_t-1]; tr = t[pos_t]
        ans = min( i-min(sl,tl), max(sr,tr)-i, (sr-i) + (sr-tl), (tr-i) + (tr-sl), (i-sl) + (tr-sl), (i-tl) + (sr-tl) )
        print(ans)

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

a,b,q=list(map(int,input().split()))
s = []
t = []
for i in range(a):
  s.append(int(eval(input())))
for i in range(b):
  t.append(int(eval(input())))
for _ in range(q):
  x = int(eval(input()))
  
  ans = [0,0,0]
  
  if x in s:
    sl = 0
    sr = 0
  else:
    i = bisect.bisect_left(s,x)
    if i == 0:
      sl = 100000000000
    else:
      sl = abs(s[i-1]-x)
    if i == a:
      sr = 100000000000
    else:
      sr = abs(s[i]-x)
  if x in t:
    tl = 0
    tr = 0
  else:
    i = bisect.bisect_left(t,x)
    if i == 0:
      tl = 100000000000
    else:
      tl = abs(t[i-1]-x)
    if i == b:
      tr = 100000000000
    else:
      tr = abs(t[i]-x)
  ans[0] = max(tl,sl)
  ans[1] = max(tr,sr)
  ans[2] = min(2*tl+sr,2*sl+tr,2*sr+tl,2*tr+sl)
  print((min(ans)))

# Optimized solution
import bisect

a,b,q=list(map(int,input().split()))
s = []
t = []
for i in range(a):
  s.append(int(eval(input())))
for i in range(b):
  t.append(int(eval(input())))
for _ in range(q):
  x = int(eval(input()))
  
  ans = [0,0,0]
  
  i = bisect.bisect_left(s,x)
  if i == 0:
    sl = 100000000000
  else:
    sl = abs(s[i-1]-x)
  if i == a:
    sr = 100000000000
  else:
    sr = abs(s[i]-x)
  i = bisect.bisect_left(t,x)
  if i == 0:
    tl = 100000000000
  else:
    tl = abs(t[i-1]-x)
  if i == b:
    tr = 100000000000
  else:
    tr = abs(t[i]-x)
  ans[0] = max(tl,sl)
  ans[1] = max(tr,sr)
  ans[2] = min(2*tl+sr,2*sl+tr,2*sr+tl,2*tr+sl)
  print((min(ans)))
# Original solution
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().split()])


# ===CODE===

def disLR(a, idx):
    small = a[max(0, idx - 1)]
    large = a[min(len(a) - 1, idx)]
    return small, large


def main():
    a, b, q = ns()
    s = [ni() for _ in range(a)]
    t = [ni() for _ in range(b)]

    for _ in range(q):
        ans = INF

        x = ni()
        tmpans = [0] * 4

        idxs = bisect.bisect_left(s, x)
        sml, lrg = disLR(s, idxs)
        tmpans[0] += abs(x - sml)
        tmpans[1] += abs(x - lrg)
        idxsml = bisect.bisect_left(t, sml)
        tmpans[0] += min([abs(sml - i) for i in disLR(t, idxsml)])
        idxlrg = bisect.bisect_left(t, lrg)
        tmpans[1] += min([abs(lrg - i) for i in disLR(t, idxlrg)])

        idxt = bisect.bisect_left(t, x)
        sml, lrg = disLR(t, idxt)
        tmpans[2] += abs(x - sml)
        tmpans[3] += abs(x - lrg)
        idxsml = bisect.bisect_left(s, sml)
        tmpans[2] += min([abs(sml - i) for i in disLR(s, idxsml)])
        idxlrg = bisect.bisect_left(s, lrg)
        tmpans[3] += min([abs(lrg - i) for i in disLR(s, idxlrg)])
        ans = min(ans, min(tmpans))
        print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: list(map(int, sys.stdin.readline().split()))
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().split()])


# ===CODE===

def disLR(a, idx):
    small = a[max(0, idx - 1)]
    large = a[min(len(a) - 1, idx)]
    return [small, large]


def main():
    a, b, q = ns()
    s = [ni() for _ in range(a)]
    t = [ni() for _ in range(b)]

    for _ in range(q):
        ans = INF

        x = ni()

        idxs = bisect.bisect_left(s, x)
        a1 = disLR(s, idxs)

        idxt = bisect.bisect_left(t, x)
        a2 = disLR(t, idxt)

        for ta1 in a1:
            for ta2 in a2:
                tmp1 = abs(x - ta1) + abs(ta2 - ta1)
                tmp2 = abs(x - ta2) + abs(ta1 - ta2)
                ans = min(ans, tmp1, tmp2)

        print(ans)


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

a, b, q = list(map(int, input().split()))
ss = sorted([int(eval(input())) for _ in range(a)])
ts = sorted([int(eval(input())) for _ in range(b)])
xs = [int(eval(input())) for _ in range(q)]

for x in xs:
    sindex = bisect.bisect(ss, x)
    if sindex == 0:
        sl = float('inf')
        sr = ss[sindex] - x
    elif sindex == a:
        sl = x - ss[sindex - 1]
        sr = float('inf')
    else:
        sl = x - ss[sindex - 1]
        sr = ss[sindex] - x
    tindex = bisect.bisect(ts, x)
    if tindex == 0:
        tl = float('inf')
        tr = ts[tindex] - x
    elif tindex == b:
        tl = x - ts[tindex - 1]
        tr = float('inf')
    else:
        tl = x - ts[tindex - 1]
        tr = ts[tindex] - x
    print((
        min([
            max(sl, tl),
            max(sr, tr),
            2 * sl + tr,
            2 * tl + sr,
            2 * sr + tl,
            2 * tr + sl,
        ])))

# Optimized solution
import bisect

a, b, q = list(map(int, input().split()))
ss = sorted([int(eval(input())) for _ in range(a)] + [float('inf'), -float('inf')])
ts = sorted([int(eval(input())) for _ in range(b)] + [float('inf'), -float('inf')])
xs = [int(eval(input())) for _ in range(q)]

for x in xs:
    sindex = bisect.bisect(ss, x)
    sl = x - ss[sindex - 1]
    sr = ss[sindex] - x
    tindex = bisect.bisect(ts, x)
    tl = x - ts[tindex - 1]
    tr = ts[tindex] - x
    print((
        min([
            max(sl, tl),
            max(sr, tr),
            2 * sl + tr,
            2 * tl + sr,
            2 * sr + tl,
            2 * tr + sl,
        ])))
# Original solution
from bisect import bisect

num_a,num_b,num_q = list(map(int, input().split(' ')))

lsa = [int(eval(input())) for _ in range(num_a)]
lsb = [int(eval(input())) for _ in range(num_b)]
lsa.sort()
lsb.sort()
# print(lsa)
# print(lsb)
lsq = [int(eval(input())) for _ in range(num_q)]

for ques in lsq:
    lower_bound_a = bisect(lsa, ques)
    lower_bound_b = bisect(lsb, ques)
    upper_bound_a = lower_bound_a - 1
    upper_bound_b = lower_bound_b - 1

    min_cand = 9223372036854775807
    if lower_bound_a < num_a and lower_bound_b < num_b:
        min_cand = min(min_cand, max(lsa[lower_bound_a], lsb[lower_bound_b]) - ques)
    if upper_bound_a >= 0 and upper_bound_b >= 0:
        min_cand = min(min_cand, ques - min(lsa[upper_bound_a], lsb[upper_bound_b]))
    if upper_bound_a >= 0 and lower_bound_b < num_b:
        min_cand = min(
            min_cand, 
            lsb[lower_bound_b] - ques + lsb[lower_bound_b] - lsa[upper_bound_a],
            ques - lsa[upper_bound_a] + lsb[lower_bound_b] - lsa[upper_bound_a],
        )
    if lower_bound_a < num_a and upper_bound_b >= 0:
        min_cand = min(
            min_cand, 
            lsa[lower_bound_a] - ques + lsa[lower_bound_a] - lsb[upper_bound_b],
            ques - lsb[upper_bound_b] + lsa[lower_bound_a] - lsb[upper_bound_b],
        )
    
    print(min_cand)


# Optimized solution
from bisect import bisect
LONG_MIN = -9223372036854775808
LONG_MAX = 9223372036854775807

num_a,num_b,num_q = list(map(int, input().split(' ')))
lsa = [int(eval(input())) for _ in range(num_a)] + [LONG_MIN, LONG_MAX]
lsb = [int(eval(input())) for _ in range(num_b)] + [LONG_MIN, LONG_MAX]
lsa.sort()
lsb.sort()
lsq = [int(eval(input())) for _ in range(num_q)]

for ques in lsq:
    lower_bound_a = bisect(lsa, ques)
    lower_bound_b = bisect(lsb, ques)
    upper_bound_a = lower_bound_a - 1
    upper_bound_b = lower_bound_b - 1

    res = min(
        max(lsa[lower_bound_a], lsb[lower_bound_b]) - ques, 
        ques - min(lsa[upper_bound_a], lsb[upper_bound_b]),
        lsb[lower_bound_b] - ques + lsb[lower_bound_b] - lsa[upper_bound_a],
        ques - lsa[upper_bound_a] + lsb[lower_bound_b] - lsa[upper_bound_a],
        lsa[lower_bound_a] - ques + lsa[lower_bound_a] - lsb[upper_bound_b],
        ques - lsb[upper_bound_b] + lsa[lower_bound_a] - lsb[upper_bound_b],
    )
    
    print(res)
# Original solution
A,B,Q=list(map(int,input().split()))
s=[]
t=[]
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=int(eval(input()))
  s1=s[:]
  s1.append(x)
  s1.sort()
  j=s1.index(x)
  if j==0:
    kouhoA=[s[j]]
  elif j==A:
    kouhoA=[s[j-1]]
  else:
    kouhoA=[s[j],s[j-1]]
  t1=t[:]
  t1.append(x)
  t1.sort()
  k=t1.index(x)
  if k==0:
    kouhoB=[t[k]]
  elif k==B:
    kouhoB=[t[k-1]]
  else:
    kouhoB=[t[k],t[k-1]]
  if len(kouhoA)==1:
    
    if len(kouhoB)==1:
      a=abs(kouhoA[0]-kouhoB[0])
      ans=min([abs(x-kouhoA[0])+a,abs(x-kouhoB[0])+a])
    else:
      u=abs(x-kouhoA[0])
      a=abs(kouhoA[0]-kouhoB[0])
      b=abs(kouhoA[0]-kouhoB[1])
      ans=min([u+a,abs(x-kouhoB[0])+a,u+b,abs(x-kouhoB[1])+b])
  else:
    if len(kouhoB)==1:
      a=abs(kouhoA[0]-kouhoB[0])
      c=abs(kouhoB[0]-kouhoA[1])
      v=abs(x-kouhoB[0])
      ans=min([abs(x-kouhoA[0])+a,v+a,abs(x-kouhoA[1])+c,v+c])
    else:
      u=abs(x-kouhoA[0])
      a=abs(kouhoA[0]-kouhoB[0])
      b=abs(kouhoA[0]-kouhoB[1])
      c=abs(kouhoB[0]-kouhoA[1])
      d=abs(kouhoA[1]-kouhoB[1])
      v=abs(x-kouhoB[0])
      w=abs(x-kouhoA[1])
      y=abs(x-kouhoB[1])
      ans=min([u+a,v+a,w+d,y+d,w+c,v+c,u+b,y+b])
  print(ans)


# Optimized solution
import bisect
A,B,Q=list(map(int,input().split()))
s=[]
t=[]
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=int(eval(input()))
  j=bisect.bisect_left(s,x)
  if j==0:
    kouhoA=[s[j]]
  elif j==A:
    kouhoA=[s[j-1]]
  else:
    kouhoA=[s[j],s[j-1]]
  k=bisect.bisect_left(t,x)
  if k==0:
    kouhoB=[t[k]]
  elif k==B:
    kouhoB=[t[k-1]]
  else:
    kouhoB=[t[k],t[k-1]]
  if len(kouhoA)==1:
    
    if len(kouhoB)==1:
      a=abs(kouhoA[0]-kouhoB[0])
      ans=min([abs(x-kouhoA[0])+a,abs(x-kouhoB[0])+a])
    else:
      u=abs(x-kouhoA[0])
      a=abs(kouhoA[0]-kouhoB[0])
      b=abs(kouhoA[0]-kouhoB[1])
      ans=min([u+a,abs(x-kouhoB[0])+a,u+b,abs(x-kouhoB[1])+b])
  else:
    if len(kouhoB)==1:
      a=abs(kouhoA[0]-kouhoB[0])
      c=abs(kouhoB[0]-kouhoA[1])
      v=abs(x-kouhoB[0])
      ans=min([abs(x-kouhoA[0])+a,v+a,abs(x-kouhoA[1])+c,v+c])
    else:
      u=abs(x-kouhoA[0])
      a=abs(kouhoA[0]-kouhoB[0])
      b=abs(kouhoA[0]-kouhoB[1])
      c=abs(kouhoB[0]-kouhoA[1])
      d=abs(kouhoA[1]-kouhoB[1])
      v=abs(x-kouhoB[0])
      w=abs(x-kouhoA[1])
      y=abs(x-kouhoB[1])
      ans=min([u+a,v+a,w+d,y+d,w+c,v+c,u+b,y+b])
  print(ans)
# 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)]
import bisect

inf=10**11

def tansak(lis,lis2,dis):
    ind=bisect.bisect_left(lis,dis)
    ind2=bisect.bisect_left(lis2,dis)
    return ind,ind2

for i in range(q):
    now = x[i]
    ind,ind2 = tansak(s,t,now)
    if  ind==0:
        one=-inf
    else:
        one=s[ind-1]
    if ind==a:
        two=inf
    else:
        two=s[ind]
    if ind2==0:
        thr=-inf
    else:
        thr=t[ind2-1]
    if ind2==b:
        fo=inf
    else:
        fo=t[ind2]
    tmp1=max(two,fo)-now
    tmp2=2*two-thr-now
    tmp3=2*fo-one-now
    tmp4=now-min(one,thr)
    tmp5=now-thr+two-thr
    tmp6=now-one+fo-one
    print((min(tmp1,tmp2,tmp3,tmp4,tmp5,tmp6)))


# Optimized solution
import sys
import math
def input():
    return sys.stdin.readline()[:-1]
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)]
import bisect

inf=10**11

def tansak(lis,lis2,dis):
    ind=bisect.bisect_left(lis,dis)
    ind2=bisect.bisect_left(lis2,dis)
    return ind,ind2

for i in range(q):
    now = x[i]
    ind,ind2 = tansak(s,t,now)
    if  ind==0:
        one=-inf
    else:
        one=s[ind-1]
    if ind==a:
        two=inf
    else:
        two=s[ind]
    if ind2==0:
        thr=-inf
    else:
        thr=t[ind2-1]
    if ind2==b:
        fo=inf
    else:
        fo=t[ind2]
    tmp1=max(two,fo)-now
    tmp2=2*two-thr-now
    tmp3=2*fo-one-now
    tmp4=now-min(one,thr)
    tmp5=now-thr+two-thr
    tmp6=now-one+fo-one
    print((min(tmp1,tmp2,tmp3,tmp4,tmp5,tmp6)))
# Original solution
import bisect
from sys import stdin
readline=stdin.readline
a,b,q=list(map(int,input().split()))
s=sorted([int(readline()) for i in range(a)])
t=sorted([int(readline()) for i in range(b)])
for i in range(q):
    ans=999999999999
    x=int(readline())
    w=bisect.bisect_left(s,x)
    for j in range(2):
        if not 0<=w-j<len(s):
            continue
        z=bisect.bisect_left(t,s[w-j])
        for k in range(2):
            if not 0<=z-k<len(t):
                continue
            ans=min(ans,abs(x-s[w-j])+abs(s[w-j]-t[z-k]))
    w=bisect.bisect_left(t,x)
    for j in range(2):
        if not 0<=w-j<len(t):
            continue
        z=bisect.bisect_left(s,t[w-j])
        for k in range(2):
            if not 0<=z-k<len(s):
                continue
            ans=min(ans,abs(x-t[w-j])+abs(t[w-j]-s[z-k]))
    print(ans)

# Optimized solution
import bisect
from sys import stdin
readline=stdin.readline
a,b,q=list(map(int,input().rstrip().split()))
s=sorted([int(readline().rstrip()) for i in range(a)])
t=sorted([int(readline().rstrip()) for i in range(b)])
for i in range(q):
    ans=999999999999
    x=int(readline().rstrip())
    w=bisect.bisect_left(s,x)
    for j in range(2):
        if not 0<=w-j<len(s):
            continue
        z=bisect.bisect_left(t,s[w-j])
        for k in range(2):
            if not 0<=z-k<len(t):
                continue
            ans=min(ans,abs(x-s[w-j])+abs(s[w-j]-t[z-k]))
    w=bisect.bisect_left(t,x)
    for j in range(2):
        if not 0<=w-j<len(t):
            continue
        z=bisect.bisect_left(s,t[w-j])
        for k in range(2):
            if not 0<=z-k<len(s):
                continue
            ans=min(ans,abs(x-t[w-j])+abs(t[w-j]-s[z-k]))
    print(ans)
# Original solution
import bisect
import sys
def input_function():
    return sys.stdin.readline().rstrip()
input=input_function
a,b,q=list(map(int,input().split()))
s=sorted([int(eval(input())) for i in range(a)])
t=sorted([int(eval(input())) for i in range(b)])
for i in range(q):
    ans=999999999999
    x=int(eval(input()))
    w=bisect.bisect_left(s,x)
    for j in range(2):
        if not 0<=w-j<len(s):
            continue
        z=bisect.bisect_left(t,s[w-j])
        for k in range(2):
            if not 0<=z-k<len(t):
                continue
            ans=min(ans,abs(x-s[w-j])+abs(s[w-j]-t[z-k]))
    w=bisect.bisect_left(t,x)
    for j in range(2):
        if not 0<=w-j<len(t):
            continue
        z=bisect.bisect_left(s,t[w-j])
        for k in range(2):
            if not 0<=z-k<len(s):
                continue
            ans=min(ans,abs(x-t[w-j])+abs(t[w-j]-s[z-k]))
    print(ans)

# Optimized solution
import bisect
import sys
input=lambda : sys.stdin.readline().rstrip()
a,b,q=list(map(int,input().split()))
s=sorted([int(eval(input())) for i in range(a)])
t=sorted([int(eval(input())) for i in range(b)])
for i in range(q):
    ans=999999999999
    x=int(eval(input()))
    w=bisect.bisect_left(s,x)
    for j in range(2):
        if not 0<=w-j<len(s):
            continue
        z=bisect.bisect_left(t,s[w-j])
        for k in range(2):
            if not 0<=z-k<len(t):
                continue
            ans=min(ans,abs(x-s[w-j])+abs(s[w-j]-t[z-k]))
    w=bisect.bisect_left(t,x)
    for j in range(2):
        if not 0<=w-j<len(t):
            continue
        z=bisect.bisect_left(s,t[w-j])
        for k in range(2):
            if not 0<=z-k<len(s):
                continue
            ans=min(ans,abs(x-t[w-j])+abs(t[w-j]-s[z-k]))
    print(ans)
# Original solution
import bisect
import sys
input=lambda : sys.stdin.readline().rstrip()
a,b,q=list(map(int,input().split()))
s=sorted([int(eval(input())) for i in range(a)])
t=sorted([int(eval(input())) for i in range(b)])
for i in range(q):
    ans=999999999999
    x=int(eval(input()))
    w=bisect.bisect_left(s,x)
    for j in range(2):
        if not 0<=w-j<len(s):
            continue
        z=bisect.bisect_left(t,s[w-j])
        for k in range(2):
            if not 0<=z-k<len(t):
                continue
            ans=min(ans,abs(x-s[w-j])+abs(s[w-j]-t[z-k]))
    w=bisect.bisect_left(t,x)
    for j in range(2):
        if not 0<=w-j<len(t):
            continue
        z=bisect.bisect_left(s,t[w-j])
        for k in range(2):
            if not 0<=z-k<len(s):
                continue
            ans=min(ans,abs(x-t[w-j])+abs(t[w-j]-s[z-k]))
    sys.stdout.write("%d"%ans+'\n')

# Optimized solution
import bisect
import sys
input=lambda : sys.stdin.readline().rstrip()
a,b,q=list(map(int,input().split()))
s=sorted([int(eval(input())) for i in range(a)])
t=sorted([int(eval(input())) for i in range(b)])
for i in range(q):
    ans=999999999999
    x=int(eval(input()))
    w=bisect.bisect_left(s,x)
    for j in range(2):
        if not 0<=w-j<len(s):
            continue
        z=bisect.bisect_left(t,s[w-j])
        for k in range(2):
            if not 0<=z-k<len(t):
                continue
            ans=min(ans,abs(x-s[w-j])+abs(s[w-j]-t[z-k]))
    w=bisect.bisect_left(t,x)
    for j in range(2):
        if not 0<=w-j<len(t):
            continue
        z=bisect.bisect_left(s,t[w-j])
        for k in range(2):
            if not 0<=z-k<len(s):
                continue
            ans=min(ans,abs(x-t[w-j])+abs(t[w-j]-s[z-k]))
    print(ans)
# Original solution
from bisect import bisect
A,B,Q=list(map(int, input().split()))
s=[int(eval(input())) for _ in range(A)] + [99**99]
t=[int(eval(input())) for _ in range(B)] + [99**99]
for _ in range(Q):
	x = int(eval(input()))
	ans = []
	ps = bisect(s, x)
	pt = bisect(t, x)
	for vs in (s[ps], s[ps-1]):
		for vt in (t[pt], t[pt-1]):
			ans.append(abs(x - vs) + abs(vs - vt))
			ans.append(abs(x - vt) + abs(vt - vs))
	print((min(ans)))


# Optimized solution
from bisect import bisect
A,B,Q=list(map(int, input().split()))
s=[int(eval(input())) for _ in range(A)] + [10**11]
t=[int(eval(input())) for _ in range(B)] + [10**11]
for _ in range(Q):
	x = int(eval(input()))
	ans = []
	ps = bisect(s, x)
	pt = bisect(t, x)
	for vs in (s[ps], s[ps-1]):
		for vt in (t[pt], t[pt-1]):
			ans.append(abs(x - vs) + abs(vs - vt))
			ans.append(abs(x - vt) + abs(vt - vs))
	print((min(ans)))
# Original solution
x=[]
for i,j in enumerate(map(int,input().split())):
    c=[]
    for l in range(j):
        t=int(eval(input()))
        x.append((i,l,t))
        c.append([t])
x.sort(key=lambda x:x[2])
l=[-10**20]*2
for y in x:
    if y[0] != 2: 
        l[y[0]]=y[2]
    else:
        c[y[1]]+=l[:]
l=[10**20]*2
for y in x[::-1]:
    if y[0] != 2: 
        l[y[0]]=y[2]
    else:
        c[y[1]]+=l[:]
print(("\n".join(str(min(d[0]-min(d[1],d[2]),max(d[3],d[4])-d[0],
        d[4]-d[1]+min(d[0]-d[1],d[4]-d[0]),
        d[3]-d[2]+min(d[0]-d[2],d[3]-d[0])
        )) for d in c)
        ))


# Optimized solution
import sys
input = sys.stdin.readline
A, B, Q = list(map(int, input().split()))
inf = 10**18
S = [-inf]
for _ in range(A):
    S.append(int(eval(input())))
S.append(inf)
T = [-inf]
for _ in range(B):
    T.append(int(eval(input())))
T.append(inf)
def f_s(x, l):
    mn, mx = -1, len(l)
    idx = mx//2
    while mx-mn>1:
        if l[idx] < x:
            idx, mn = (idx + mx)//2, idx
            continue
        idx, mx = (idx + mn)//2, idx
    return idx

for _ in range(Q):
    q = int(eval(input()))
    xi, yi = f_s(q, S), f_s(q, T)
    s1, s2 = S[xi], S[xi+1]
    t1, t2 = T[yi], T[yi+1]
    print((min([
        max(q-s1,q-t1),
        max(s2-q, t2-q),
        2*(s2-q) + q-t1,
        2*(t2-q) + q-s1,
        2*(q-s1) + t2-q,
        2*(q-t1) + s2-q,
        ])))
#    print(q, s1, s2, t1, t2)

#    print(S[xi], T[yi])
# Original solution
import sys
from bisect import bisect_left
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

A, B, Q = list(map(int, readline().split()))
stx = list(map(int, read().split()))
s = stx[:A]; t = stx[A:-Q]; x = stx[-Q:]
s = [-10 ** 10] + s + [10 ** 11]
t = [-10 ** 10] + t + [10 ** 11]

for i in x:
    ax = bisect_left(s, i)
    bx = bisect_left(t, i)
    pp = max(s[ax], t[bx]) - i
    mm = i - min(s[ax - 1], t[bx - 1])
    pm = min(s[ax] * 2 - i - t[bx - 1], t[bx] * 2 - i - s[ax - 1])
    mp = min(i - s[ax - 1] * 2 + t[bx], i - t[bx - 1] * 2 + s[ax])
    print((min(pp, mm, pm, mp)))

# Optimized solution
import sys
from bisect import bisect_left
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():
    A, B, Q = list(map(int, readline().split()))
    stx = list(map(int, read().split()))
    s = stx[:A]; t = stx[A:-Q]; x = stx[-Q:]
    s = [-10 ** 10] + s + [10 ** 11]
    t = [-10 ** 10] + t + [10 ** 11]

    for i in x:
        ax = bisect_left(s, i)
        bx = bisect_left(t, i)
        pp = max(s[ax], t[bx]) - i
        mm = i - min(s[ax - 1], t[bx - 1])
        pm = min(s[ax] * 2 - i - t[bx - 1], t[bx] * 2 - i - s[ax - 1])
        mp = min(i - s[ax - 1] * 2 + t[bx], i - t[bx - 1] * 2 + s[ax])
        print((min(pp, mm, pm, mp)))


if __name__ == '__main__':
    main()