CodeEff/ECCO huggingface dataset:
# Original solution
from collections import Counter
N = int(eval(input()))
A_arr = list(map(int, input().split()))

A_arr = sorted(A_arr, reverse=True)
C_arr = Counter(A_arr)

count = 0
while len(A_arr) != 0:
    v_max = A_arr.pop(0)
    C_arr[v_max] -= 1
    v_pair = 2**v_max.bit_length() - v_max
    if C_arr[v_pair] != 0:
        A_arr.remove(v_pair)
        C_arr[v_pair] -= 1
        count += 1
    else:
        pass

print(count)

# Optimized solution
from collections import Counter
N = int(eval(input()))
A_arr = list(map(int, input().split()))

A_arr = sorted(A_arr, reverse=True)
C_arr = Counter(A_arr)

count = 0
for i in range(N):
    v_max = A_arr[i]
    if C_arr[v_max] == 0:
        continue
    C_arr[v_max] -= 1
    v_pair = 2**v_max.bit_length() - v_max
    if C_arr[v_pair] > 0:
        C_arr[v_pair] -= 1
        count += 1
    else:
        pass

print(count)
# Original solution
n=int(eval(input()))
lists=list(map(int,input().split()))
lists=sorted(lists,reverse=True)
from collections import Counter
dic=dict(Counter(lists))

ans=0
howmuch=[[] for i in range(30)]
for num in lists:
    c=0
    while num%2==0:
        num=num//2
        c+=1
    howmuch[c].append(num)
for i in range(30):
    if len(howmuch[i])<=1:
        pass
    else:
        dic=dict(Counter(howmuch[i]))
        for some in howmuch[i]:
            for j in range(1,30):
                if 2**j-some in list(dic.keys()) and dic[some]>0 and dic[2**j-some]>0:
                    if some!=2**(j-1):
                        m=min(dic[some],dic[2**j-some])
                        dic[some]-=m
                        dic[2**j-some]-=m
                        ans+=m
                    elif some==2**(j-1):
                        ans+=dic[some]//2
                        dic[some]=dic[some]%2

print(ans)    
    
    
  

# Optimized solution

from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0

D = defaultdict(int)
for x in A:
    D[x] += 1
A.sort(reverse=True)

for x in A:
    for i in range(1, 31):
        if D[x] > 0:
            if 2**i-x in list(D.keys()) and D[2**i-x] > 0:
                if 2**(i-1) != x:
                    ans += 1
                    D[x] -= 1
                    D[2**i-x] -= 1
for i in range(31):
    ans += D[2**i]//2
print(ans)
# Original solution
import math,collections
n=int(eval(input()))
a=sorted(map(int,input().split()))[::-1]
s=collections.Counter(a)
r=0
f=0
for i,v in enumerate(a):
	if f:f=0;continue
	if s[v]==0:continue
	p=2**math.ceil(math.log2(v))-v
	if p in list(s.keys()) and s[p]>0:s[v]-=1;s[p]-=1;r+=1;continue
	if i<n-1 and p==0 and a[i+1]==v and s[v]>=2:s[v]-=2;r+=1;f=1
print(r)

# Optimized solution
import math,collections
n=int(eval(input()))
a=sorted(map(int,input().split()))[::-1]
s=collections.Counter(a)
r=0
f=0
for i,v in enumerate(a):
	p=2**math.ceil(math.log2(v))-v
	if f:f=0
	elif s[v]==0:pass
	elif p in list(s.keys())and s[p]>0:s[v]-=1;s[p]-=1;r+=1
	elif i<n-1 and p==0 and v==a[i+1]and s[v]>1:s[v]-=2;r+=1;f=1
print(r)
# Original solution
N = int(eval(input()))
A = [int(_) for _ in input().split()]

from collections import defaultdict

xs = sorted(A, reverse=True)

cs = defaultdict(int)

for x in xs:
    cs[x] += 1

result = 0

for x in xs:
    if cs[x]:
        for i in range(31, 0, - 1):
            m = 2**i
            y = m - x
            if x == y:
                if cs[y] >= 2:
                    cs[y] -= 2
                    result += 1
                    break
            else:
                if cs[y] >= 1:
                    cs[x] -= 1
                    cs[y] -= 1
                    result += 1
                    break

#print(cs)
print(result)


# Optimized solution
N = int(eval(input()))
A = [int(_) for _ in input().split()]

xs = sorted(A, reverse=True)

cs = {}

for x in xs:
    cs[x] = cs.get(x, 0) + 1

result = 0

for x in xs:
    if cs[x]:
        for i in range(31, 0, - 1):
            m = 2**i
            y = m - x
            if y > x or y < 1:
                continue
            if y in cs:
                if x == y:
                    if cs[y] >= 2:
                        cs[y] -= 2
                        result += 1
                        break
                else:
                    if cs[y] >= 1:
                        cs[x] -= 1
                        cs[y] -= 1
                        result += 1
                        break

#print(cs)
print(result)
# Original solution
N=int(eval(input()))
A=list(map(int,input().split()))
import math
import collections
powers =[2**i for i in range(1,int(math.log(max(A),2)+2))]
table=collections.defaultdict(int)
table2=collections.defaultdict(set)
ans=0
for i in range(N):
  table[A[i]]+=1
for x in table:
  for y in reversed(powers):
    if y - x in table:
      table2[x].add(y-x)
        
        
        
table2 =list(table2.items())
table2.sort(key = lambda x:len(x[1]))

for x,y in table2:
  while(table[x]>0):
    table[x]-=1
    for z in y:
      if table[z]>0:
        ans+=1
        table[z]-=1
        break
print(ans)  
      



# Optimized solution
def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline

    _ = int(eval(input()))
    A = [int(i) for i in input().split()]

    ans = 0
    c = Counter(A)
    B = sorted(list(c.keys()), reverse=True)

    for b in B:
        if c[b] == 0:
            continue
        a = (2 ** b.bit_length()) - b
        if a == b:
            cur = c[b]//2
        else:
            if a in c:
                cur = min(c[a], c[b])
            else:
                cur = 0
        ans += cur
        # c[b] -= cur
        c[a] -= cur

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc 029 B
"""

from collections import Counter

n = int(eval(input()))
ali = list(map(int, input().split()))
ali.sort(reverse=True)

c = Counter(ali)
ans = 0


def pow2(n):
    m = n
    tmp = 1
    while m > 0:
        tmp = tmp << 1
        m = m >> 1
    return tmp


ii = 0
m = ali[ii]
while bool(c):
    n = pow2(m) - m
    c[m] -= 1
    if c[m] == 0:
        c += Counter()
        ii += 1
        m = ali[ii]
    if n in c:
        c[n] -= 1
        ans += 1
    c += Counter()

print(ans)








# Optimized solution
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc 029 B
"""

from collections import Counter

nn = int(eval(input()))
ali = list(map(int, input().split()))
ali.sort(reverse=True)

c = Counter(ali)
ans = 0


def pow2(n):
    m = n
    tmp = 1
    while m > 0:
        tmp = tmp << 1
        m = m >> 1
    return tmp


ii = 0
m = ali[ii]
while bool(c):
    while c[ali[ii]] == 0:
        ii += 1
    m = ali[ii]
    n = pow2(m) - m
    c[m] -= 1
    if c[m] <= 0:
        del c[m]
    if n in c:
        c[n] -= 1
        if c[n] <= 0:
            del c[n]
        ans += 1

print(ans)
# Original solution

import bisect

"""
def wantp(n):

    wq = []
    while p[n] != n:
        wq.append(n)
        n = p[n]

    for i in wq:
        p[i] = n

    return n
"""


N = int(eval(input()))

A = list(map(int,input().split()))
A.sort()

"""
p = [i for i in range(N)]
rank = [1] * N
"""
used = [False] * N
ans = 0

for i in range(N):

    i = N - 1 - i
    now = 2 ** 33

    while A[i] * 2 < now:
        now //= 2

    na = A[-1]
    del A[-1]

    if used[i]:
        continue

    ind = bisect.bisect_left(A,now-na)

    while ind < i and used[ind] and na + A[ind] == now:
        ind += 1

    if ind < i and na + A[ind] == now:
        used[ind] = True
        ans += 1

    #print (now,na,ind)

print (ans)
        


# Optimized solution

import bisect

"""
def wantp(n):

    wq = []
    while p[n] != n:
        wq.append(n)
        n = p[n]

    for i in wq:
        p[i] = n

    return n
"""


N = int(eval(input()))

B = list(map(int,input().split()))
B.sort()

A = []
AS = []
for i in range(N):
    if len(A) == 0:
        A.append(B[0])
        AS.append(1)
    else:
        if A[-1] == B[i]:
            AS[-1] += 1
        else:
            A.append(B[i])
            AS.append(1)


"""
p = [i for i in range(N)]
rank = [1] * N
"""
ans = 0

for i in range(len(A)):

    i = len(A) - 1 - i
    now = 2 ** 33

    while A[i] * 2 < now:
        now //= 2

    ind = bisect.bisect_left(A,now-A[i])

    if A[ind] + A[i] == now:

        if ind == i:
            ans += AS[i] // 2
            AS[i] = AS[i] % 2

        else:
            ans += min(AS[i],AS[ind])
            AS[ind] = max(AS[ind] - AS[i] , 0)



    #print (now,na,ind)

print (ans)
# Original solution

N = int(eval(input()))

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

"""

2べきになる条件は？
→片方が2の補数であること

Nが大きい→貪欲的に
最大の奴はそれより小さい奴としかペアを組めない
→大きい奴から貪欲にとっけいけばいける？

いけそうかなぁ
"""

A.sort()
An = []
for i in range(N):
    if i == 0 or An[-1][0] != A[i]:
        An.append([ A[i] , 1 ])
    else:
        An[-1][1] += 1

import bisect
ans = 0

#print (An)

for i in range(len(An)-1,-1,-1):

    for j in range(An[i][1]):

        An[i][1] -= 1

        for k in range(30,-1,-1):
            if 2**k <= An[i][0]:
                continue

            ind = bisect.bisect_left(An,[2**k - An[i][0],0])
            if ind < len(An) and An[ind][0] == 2**k - An[i][0] and An[ind][1] > 0:
                An[ind][1] -= 1
                ans += 1
                break

print (ans)

# Optimized solution

N = int(eval(input()))

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

"""

2べきになる条件は？
→片方が2の補数であること

Nが大きい→貪欲的に
最大の奴はそれより小さい奴としかペアを組めない
→大きい奴から貪欲にとっけいけばいける？

いけそうかなぁ
"""

A.sort()
dic = {}
lis = []

for i in range(N):
    
    if i == 0 or A[i-1] != A[i]:
        dic[A[i]] = 1
        lis.append(A[i])
    else:
        dic[A[i]] += 1

lis.reverse()
ans = 0
d2lis = {}
for i in range(32):
    d2lis[2**i] = i

import math

for i in lis:

    if i in d2lis:
        ans += dic[i]//2
        dic[i] %= 2
    else:
        t = 2 ** (int(math.log(i,2)) + 1)
        if t-i in dic:
            ans += min(dic[i],dic[t-i])
            dic[t-i] = max(0, dic[t-i]-dic[i])

print (ans)
# Original solution
N = int(eval(input()))
ball = list(map(int, input().split()))
ball.sort(reverse = True)
dic = {}
for i in range(ball[0] + 1):
    dic[i] = 0
for x in ball:
    dic[x] += 1

ans = 0
for x in ball:
    if dic[x] != 0:
        y = 2**(x.bit_length()) - x
        if dic[y] != 0:
            if y == x and dic[y] == 1: 
                continue
            ans += 1
            dic[x] -= 1
            dic[y] -= 1
print(ans)

# Optimized solution
N = int(eval(input()))
ball = list(map(int, input().split()))
ball.sort(reverse = True)
ok = {}
for x in ball:
    if x in ok:
        ok[x] += 1
    else:
        ok[x] = 1
ans = 0
for x in ball:
    if ok[x] != 0:
        y = 2**(x.bit_length()) - x
        if y in ok:
            if ok[y] != 0:
                if y == x and ok[y] == 1: 
                    continue
                ans += 1
                ok[x] -= 1
                ok[y] -= 1
print(ans)
# Original solution
from collections import defaultdict
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort(key=lambda x:-x)
d = defaultdict(int)
for i in a:
    d[i] += 1
beki = [2**i for i in range(60,0,-1)]
ans = 0
for i in a:
    if d[i] == 0:
        continue
    for j in beki:
        if j <= i:
            break
        ni = j - i
        if ni == i:
            if d[i] >= 2:
                ans +=1
                d[i]-=2
                break
        elif d[ni] > 0:
            ans += 1
            d[ni]-=1
            d[i]-=1
            break
print(ans)

# Optimized solution
from collections import defaultdict
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort(key=lambda x:-x)
d = defaultdict(int)
for i in a:
    d[i] += 1
beki = [2**i for i in range(32,0,-1)]
ans = 0
for i in a:
    if d[i] == 0:
        continue
    for j in beki:
        if j <= i:
            break
        ni = j - i
        if ni == i:
            if d[i] >= 2:
                ans +=1
                d[i]-=2
                break
        elif d[ni] > 0:
            ans += 1
            d[ni]-=1
            d[i]-=1
            break
print(ans)
# Original solution
import bisect
from collections import Counter
n = int(eval(input()))
A = list(map(int,input().split()))
A.sort()
C = Counter(A)
ans = 0
for i in range(n-1,-1,-1):
    temp = A[i]
    beki = 1
    while beki <= temp:
        beki *= 2
    counterpart = beki-temp
    if C[counterpart] > 0 and C[temp] > 0 and counterpart != temp:
        C[counterpart] -= 1
        C[temp] -= 1
        ans += 1
    elif counterpart == temp and C[counterpart] > 1:
        C[counterpart] -= 2
        ans += 1
print(ans)


# Optimized solution
from collections import Counter
n = int(eval(input()))
A = list(map(int,input().split()))
A.sort()
C = Counter(A)
ans = 0
for i in range(n-1,-1,-1):
    temp = A[i]
    beki = 1
    if C[temp] == 0:
        continue
    while beki <= temp:
        beki *= 2
    counterpart = beki-temp
    if C[counterpart] > 0 and C[temp] > 0 and counterpart != temp:
        C[counterpart] -= 1
        C[temp] -= 1
        ans += 1
    elif counterpart == temp and C[counterpart] > 1:
        C[counterpart] -= 2
        ans += 1
print(ans)
# Original solution
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline

N, *A = list(map(int, read().split()))

A.sort()
a = Counter(A)
answer = 0
# 可能な最大の2冪
limit = 1 << ((2 * 10 ** 9 + 1).bit_length() - 1)

while A:
    n = A.pop()
    if a[n] == 0:
        continue

    a[n] -= 1
    s = limit
    while n < s:
        b = s - n
        if a[b] > 0:
            answer += 1
            a[b] -= 1
            break
        s //= 2

print(answer)


# Optimized solution
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline

N, *A = list(map(int, read().split()))

A.sort()
a = Counter(A)
answer = 0


while A:
    n = A.pop()
    if a[n] == 0:
        continue

    a[n] -= 1
    # 実現可能な最大の2冪
    s = 1 << (2 * n).bit_length()
    while n < s:
        b = s - n
        if a[b] > 0:
            answer += 1
            a[b] -= 1
            break
        s //= 2

print(answer)
# Original solution
# input
A, B, Q = list(map(int, input().split()))
S, T, X = [], [], []
for _ in range(A):
    S.append(int(eval(input())))

for _ in range(B):
    T.append(int(eval(input())))

for _ in range(Q):
    X.append(int(eval(input())))

# end of world
EOW = 10 ** 10

# boundary info
tbounds = [(T[i+1] + T[i]) // 2 for i in range(B-1)]
sbounds = [(S[i+1] + S[i]) // 2 for i in range(A-1)]

# add pivot
tbounds.insert(0, 0)
tbounds.append(EOW)
sbounds.insert(0, 0)
sbounds.append(EOW)

# temple to shrine
ttos = []
cur = 0
for i in range(B):
    while True:
        if T[i] <= sbounds[cur]:
            break
        cur += 1
    ttos.append(cur-1)

# shrine to temple
stot = []
cur = 0
for i in range(A):
    while True:
        if S[i] <= tbounds[cur]:
            break
        cur += 1
    stot.append(cur-1)

for x in X:
    snear = 0
    while True:
        if x <= sbounds[snear]:
            break
        snear += 1
    tnears_range = list(range(max(0, stot[snear-1]), min(stot[snear-1] + 4, B)))
    best = abs(S[snear-1]-x) + abs(T[stot[snear-1]]-S[snear-1])
    for j in tnears_range:
        dist = abs(T[j]-x) + abs(S[ttos[j]]-T[j])
        if dist < best:
            best = dist
    # svisit = 0
    # tnear = 0
    # best = EOW * 2
    # # search
    # for i in range(A):
    #     tnear = stot[i]
    #     dist = abs(S[i]-x) + abs(T[tnear]-S[i])
    #     if best > dist:
    #         best = dist
    #     else:
    #         break
    # for i in range(max(0, tnear-3), min(tnear+3, B)):
    #     snear = ttos[i]
    #     dist = abs(T[i]-x) + abs(S[snear]-T[i])
    #     if best > dist:
    #         best = dist
    print(best)
    # print(min(min(abs(S[i]-x) + abs(T[nt]-S[i]) for (i, nt) in enumerate(stot)), min(abs(T[i]-x) + abs(S[ns]-T[i]) for (i, ns) in enumerate(ttos))))


# 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
a,b,q=list(map(int,input().split()))
s=[-999999999999]+[int(eval(input())) for i in range(a)]+[999999999999]
t=[-999999999999]+[int(eval(input())) for i in range(b)]+[999999999999]
x=[int(eval(input())) for i in range(q)]
for i in range(q):
  a1=s[bisect.bisect_left(s,x[i])-1]
  a2=s[bisect.bisect_left(s,x[i])]
  b1=t[bisect.bisect_left(t,x[i])-1]
  b2=t[bisect.bisect_left(t,x[i])]
  l=[]
  for j in [a1,a2]:
    for k in [b1,b2]:
      l.append(abs(j-k)+min(abs(x[i]-j),abs(x[i]-k)))
  print((min(l)))

# Optimized solution
import bisect
import sys
input=sys.stdin.readline
a,b,q=list(map(int,input().split()))
s=[-999999999999]+[int(eval(input())) for i in range(a)]+[999999999999]
t=[-999999999999]+[int(eval(input())) for i in range(b)]+[999999999999]
x=[int(eval(input())) for i in range(q)]
for i in range(q):
  a1=s[bisect.bisect_left(s,x[i])-1]
  a2=s[bisect.bisect_left(s,x[i])]
  b1=t[bisect.bisect_left(t,x[i])-1]
  b2=t[bisect.bisect_left(t,x[i])]
  l=[]
  for j in [a1,a2]:
    for k in [b1,b2]:
      l.append(abs(j-k)+min(abs(x[i]-j),abs(x[i]-k)))
  print((min(l)))
# Original solution
import sys

def main():
  input = sys.stdin.readline
  a, b, q = list(map(int, input().split()))
  s = [0]*a
  for i in range(a):
    s[i] = int(eval(input()))
  
  t = [0]*b
  for i in range(b):
    t[i] = int(eval(input()))

  s_near = [0]*a
  k = 0
  for i in range(a):
    if k == b-1:
      s_near[i] = abs(s[i]-t[b-1])
      continue
    while True:
      sub = min([abs(s[i]-t[k]), abs(s[i]-t[k+1])])
      if sub == abs(s[i]-t[k+1]):
        k += 1
        if k == b-1:
          s_near[i] = sub
          break
        continue
      else:
        s_near[i] = sub
        break
  
  t_near = [0]*b
  k = 0
  for i in range(b):
    if k == a-1:
      t_near[i] = abs(t[i]-s[a-1])
      continue
    while True:
      sub = min([abs(t[i]-s[k]), abs(t[i]-s[k+1])])
      if sub == abs(t[i]-s[k+1]):
        k += 1
        if k == a-1:
          t_near[i] = sub
          break
        continue
      else:
        t_near[i] = sub
        break
  
  
  for i in range(q):
    x = int(eval(input()))
    if x <= s[0]:
      sub1 = s[0]-x+s_near[0]
    elif x >= s[a-1]:
      sub1 = x-s[a-1]+s_near[a-1]
    else:
      l, r = 0, a
      while r-l > 1:
        k = (r+l)//2
        if x <= s[k]:
          r = k
        else:
          l = k
      sub1 = min([s[r]-x+s_near[r], x-s[l]+s_near[l]])
    
    
    if x <= t[0]:
      sub2 = t[0]-x+t_near[0]
    elif x >= t[b-1]:
      sub2 = x-t[b-1]+t_near[b-1]
    else:
      l, r = 0, b
      while r-l > 1:
        k = (r+l)//2
        if x <= t[k]:
          r = k
        else:
          l = k
      sub2 = min([t[r]-x+t_near[r], x-t[l]+t_near[l]])
    ans = min([sub1, sub2])
    print(ans)


if __name__ == "__main__":
  main()

# Optimized solution
import sys
import bisect

def main():
  input = sys.stdin.readline
  inf = pow(10, 18)
  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]
  
  for _ in range(q):
    x = int(eval(input()))
    i = bisect.bisect_left(s, x)
    j = bisect.bisect_left(t, x)
    ans = inf
    for l in range(-1, 1):
      for m in range(-1, 1):
        sub = min([abs(x-s[i+l]), abs(x-t[j+m])])+abs(s[i+l]-t[j+m])
        if ans > sub:
          ans = sub
    print(ans)

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

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

ss.sort()
ts.sort()
for x in xs:
    i = bisect.bisect_left(ss, x)
    s1 = ss[i - 1] if 0 < i else -(10 ** 20)
    s2 = ss[i] if i < A else 10 ** 20
    i = bisect.bisect_left(ts, x)
    t1 = ts[i - 1] if 0 < i else -(10 ** 20)
    t2 = ts[i] if i < B else 10 ** 20

    # s1 < x < s2
    # t1 < x < t2
    print((min(
        x - min(s1, t1),  # s1, t1
        2 * (x - s1) + (t2 - x),  # s1, t2
        2 * (t2 - x) + (x - s1),  # t2, s1
        2 * (s2 - x) + (x - t1),  # s2, t1
        2 * (x - t1) + (s2 - x),  # t1, s2
        max(s2, t2) - x,  # s2, t2
    )))


# Optimized solution
import bisect
import io
import sys

LINES = sys.stdin.read().splitlines()[::-1]


def readline():
    return LINES.pop()


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

ss.sort()
ts.sort()
for x in xs:
    i = bisect.bisect_left(ss, x)
    s1 = ss[i - 1] if 0 < i else -(10 ** 20)
    s2 = ss[i] if i < A else 10 ** 20
    i = bisect.bisect_left(ts, x)
    t1 = ts[i - 1] if 0 < i else -(10 ** 20)
    t2 = ts[i] if i < B else 10 ** 20

    # s1 < x < s2
    # t1 < x < t2
    print((min(
        x - min(s1, t1),  # s1, t1
        2 * (x - s1) + (t2 - x),  # s1, t2
        2 * (t2 - x) + (x - s1),  # t2, s1
        2 * (s2 - x) + (x - t1),  # s2, t1
        2 * (x - t1) + (s2 - x),  # t1, s2
        max(s2, t2) - x,  # s2, t2
    )))
# Original solution
read = input
# read = Read(False, """
# 1 1 3
# 1
# 10000000000
# 2
# 9999999999
# 5000000000
# """).read
A,B,Q = list(map(int, read().split(' ')))
arrA = list(map(int, [read() for i in range(A)]))
arrB = list(map(int, [read() for i in range(B)]))
arrQ = list(map(int, [read() for i in range(Q)]))
arrA.sort()
arrB.sort()
import bisect
def cs(x, arr):
    al = bisect.bisect_left(arr, x)
    return list([arr[i] for i in [i for i in range(al-1, al + 2) if i>=0 and i< len(arr)]])
def same_s(da,db):
    da = da / abs(da)
    db = db / abs(db)
    return da*db>0
    
def t(q,a,b):
    da = q - a
    db = q - b
    if(min(abs(da), abs(db)) == 0):
        return max(abs(da), abs(db))
    if same_s(da, db):
        return max(abs(da), abs(db))
    else :
        return 2*min(abs(da), abs(db)) + max(abs(da), abs(db))
for q in arrQ:
    optA = cs(q, arrA)
    optB = cs(q, arrB)
    ret = 10 ** 11
    for a in optA:
        for b in optB:
            ret = min(ret, t(q, a,b))
    print(ret)

# Optimized solution
import bisect
read = input
bisect_right = bisect.bisect_right
# @ see https://docs.python.org/zh-cn/3/library/bisect.html
a ,b , q = list(map(int, read().split()))
INF = 10**18
A =[-INF] + [int(read()) for i in range(a)] +[INF]
B =[-INF] + [int(read()) for i in range(b)] +[INF]
A.sort()
B.sort()
try:
    for i in range(q):
        x = int(read())
        sa = bisect_right(A, x)
        sb = bisect_right(B, x)
        ans = INF
        for pa in [A[sa - 1 ], A[sa]]:
            for pb in [B[sb - 1 ], B[sb]]:
                d1 = abs(x - pa) + abs(pa - pb)
                d2 = abs(x - pb) + abs(pb - pa)
                ans = min(ans, d1, d2)
        print(ans)
except:
    print((x, sa, sb))