Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from bisect import bisect_left


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
M = max(A) + max(B)
K = len(bin(M)) - 2
mask = (1 << K) - 1
k = K - 1
T = 1 << k
ans = 0
while k >= 0:
    B = [x & mask for x in B]
    B.sort()
    bit = 0
    for a in A:
        a_ = a & mask
        T1 = bisect_left(B, T - a_)
        T2 = bisect_left(B, 2 * T - a_)
        T3 = bisect_left(B, 3 * T - a_)
        T4 = bisect_left(B, 4 * T - a_)
        bit += (T4 - T3) + (T2 - T1)
        bit &= 1
    ans += bit * (1 << k)
    k -= 1
    T >>= 1
    mask >>= 1

print(ans)


### FIXED CODE ###

def solve():
    # from bisect import bisect_left
    import sys

    N = int(input())
    A = [int(x) for x in sys.stdin.readline().split()]
    B = [int(x) for x in sys.stdin.readline().split()]
    M = max(A) + max(B)
    K = len(bin(M)) - 2
    mask = (1 << K) - 1
    k = K - 1
    T = 1 << k
    ans = 0
    while k >= 0:
        for i in range(N):
            B[i] &= mask
            A[i] &= mask
        B = list(sorted(b & mask for b in B))
        A = list(sorted(a & mask for a in A))
        bit = 0
        T1, T2, T3 = 0, 0, 0
        for a in reversed(A):
            while T1 < N and a + B[T1] < T:
                T1 += 1
            while T2 < N and a + B[T2] < 2 * T:
                T2 += 1
            while T3 < N and a + B[T3] < 3 * T:
                T3 += 1
            # T1 = bisect_left(B, T - a, T1)
            # T2 = bisect_left(B, 2 * T - a, T2)
            # T3 = bisect_left(B, 3 * T - a, T3)
            # T4 = bisect_left(B, 4 * T - a, T4)
            bit += (N - T3) + (T2 - T1)
            bit &= 1
        ans += bit * T
        k -= 1
        T >>= 1
        mask >>= 1

    print(ans)


if __name__ == '__main__':
    solve()
### BUGGY CODE ###


def main():
    import sys
    input = sys.stdin.readline
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()

    import bisect
    def ok(x):
        # x以下になる組み合わせがk個以上
        cnt = 0
        for a in A:
            if a*a <= x:
                cnt -= 1
            if a > 0:
                c = x//a
                cnt += bisect.bisect_right(A, c)
            elif a < 0:
                c = (-x-1)//(-a)
                cnt += n - bisect.bisect_right(A, c)
            else:
                if x >= 0:
                    cnt += n
        cnt = cnt//2
        if cnt >= k:
            return True
        else:
            return False

    l = -10**18-1
    r = 10**18+1
    while l+1 < r:
        m = (l+r)//2
        if ok(m):
            r = m
        else:
            l = m
    print(r)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
#sys.setrecursionlimit(10**9)
input = sys.stdin.readline

import numpy as np

n, k = map(int, input().split())
A = np.array(input().split(), np.int64)
A = np.sort(A)

P = A[A>0]
Z = A[A==0]
N = A[A<0]

#t = n*(n-1)//2

def ok(x):
    # x以下になる組み合わせがk個以上
    cnt = 0
    #cnt += np.searchsorted(A, np.ceil(x/P), side='right').sum()
    cnt += np.searchsorted(A, x//P, side='right').sum()
    #cnt += n-np.searchsorted(A, np.floor(x/N), side='left').sum()
    cnt += (n-np.searchsorted(A, (-x-1)//(-N), side='right')).sum()
    if x >= 0:
        cnt += len(Z)*n
    cnt -= np.count_nonzero(A*A <= x)
    cnt = cnt//2
    if cnt >= k:
        return True
    else:
        return False

l = -10**18-1
r = 10**18+1
while l+1 < r:
    c = (l+r)//2
    if ok(c):
        r = c
    else:
        l = c
print(r)
### BUGGY CODE ###

import numpy
 
N,K=map(int,input().split())
p=list(map(int,input().split()))
ans = 0
tmp = [0]*(N-K+1)

for i in range(K):
  tmp[0] = tmp[0]+p[i]

for i in range(1,N-K+1):
  tmp[i]=tmp[i-1]-p[i-1]+p[i+K-1]

max_index=numpy.argmax(tmp)
for i in range(max_index,max_index+K):
  for j in range(1,p[i]+1):
    ans=ans+float(j*(1/p[i]))
print(ans)

### FIXED CODE ###

import numpy
 
N,K=map(int,input().split())
p=list(map(int,input().split()))
ans = 0
tmp = [0]*(N-K+1)

for i in range(K):
  tmp[0] = tmp[0]+p[i]

for i in range(1,N-K+1):
  tmp[i]=tmp[i-1]-p[i-1]+p[i+K-1]

max_index=numpy.argmax(tmp)
for i in range(max_index,max_index+K):
  ans=ans+float(((p[i]*(p[i]+1))/2)*1/p[i])
print(ans)
### BUGGY CODE ###

from collections import deque
import sys
input = sys.stdin.readline

def solve(h, w, a):
    used = [[False] * (w+2) for _ in range(h+2)]
    for r in range(h+2):
        used[r][0] = True
        used[r][-1] = True
    for c in range(w+2):
        used[0][c] = True
        used[-1][c] = True
    que = deque([])
    for r in range(h):
        for c in range(w):
            if a[r][c] == "#":
                que.append((r+1, c+1, 0))
                used[r+1][c+1] = 0
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if not used[nr][nc]:
                que.append((nr, nc, k+1))
                used[nr][nc] = True
    return k

h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a))

### FIXED CODE ###

from collections import deque

def solve(h, w, a):
    used = [[True] * (w+2) for _ in range(h+2)]
    que = deque()
    for r in range(h):
        used[r+1][1:-1] = map(lambda _:_=="#", a[r])
        for c in range(w):
            if a[r][c] == "#":
                que.append((r+1, c+1, 0))
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if not used[nr][nc]:
                que.append((nr, nc, k+1))
                used[nr][nc] = True
    return k

h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a))
### BUGGY CODE ###

x = input()
m = len(x)
x = int(x)

p = m//2
q = m%2

if q==1:
  if p==0:
    print(x)
    exit()
  else:
    a = 90
    while(p>0):
      x -= a
      a *= 100
    print(x)
    exit()
else:
  if p==0:
    print(0)
    exit()
  else:
    x = 0
    a = 9
    while(p>0):
      x += a
      a *= 100
    print(x)
    exit()  
    


### FIXED CODE ###

x = input()
m = len(x)
x = int(x)

p = m//2
q = m%2

if q==1:
  if p==0:
    print(x)
    exit()
  else:
    a = 90
    while(p>0):
      x -= a
      a *= 100
      p -= 1
    print(x)
    exit()
else:
  if p==0:
    print(0)
    exit()
  else:
    x = 0
    a = 9
    while(p>0):
      x += a
      a *= 100
      p -= 1
    print(x)
    exit()
### BUGGY CODE ###

N = int(input())
S = [input() for i in range(N)]
S.sort()

dic = {}
for i in S:
  dic[i] = 0
for i in S:
  dic[i] += 1
for i in dic:
  if dic[i] == max(dic.values()):
    print(i)

### FIXED CODE ###

N = int(input())
S = [input() for i in range(N)]
S.sort()

dic = {}
for i in S:
  dic[i] = 0
for i in S:
  dic[i] += 1
M = max(dic.values())
for i in dic:
  if dic[i] == M:
    print(i)
### BUGGY CODE ###

from collections import deque
h,w=map(int,input().split())
ch,cw=map(lambda x:int(x)-1,input().split())
dh,dw=map(lambda x:int(x)-1,input().split())
tizu=[]
d=deque()
d.appendleft([ch,cw])
cost=[[-1 for i in range(w)]for j in range(h)]
dx=[1,0,-1,0,-2,-2,-2,-2,-2,-1,-1,-1,-1,0,0,1,1,1,1,2,2,2,2,2]
dy=[0,1,0,-1,-2,-1,0,1,2,-2,-1,1,2,-2,2,-2,-1,1,2,-2,-1,0,1,2]
for i in range(h):
    tizu.append(input())
cost[ch][cw]=0
while(d):
    x,y=d.popleft()
    for i in range(4):
        nx=x+dx[i]
        ny=y+dy[i]
        ####行ったことある、かつ、コストが手前より高い
        if(nx<0 or ny<0 or nx>=h or ny>=w):
            continue
        if(cost[nx][ny]>-1 and cost[nx][ny]<=cost[x][y]):
            continue
        if(tizu[nx][ny]=='.'):
            cost[nx][ny]=cost[x][y]
            d.appendleft([nx,ny])
    
    for i in range(4,24):
        nx=x+dx[i]
        ny=y+dy[i]
        if(nx<0 or ny<0 or nx>=h or ny>=w):
            continue
        if(cost[nx][ny]>-1):
            continue
        if(tizu[nx][ny]=='.'):
            cost[nx][ny]=cost[x][y]+1
            d.append([nx,ny])

print(cost[dh][dw])

### FIXED CODE ###

from collections import deque
h,w=map(int,input().split())
ch,cw=map(lambda x:int(x)-1,input().split())
dh,dw=map(lambda x:int(x)-1,input().split())
tizu=[]
d=deque()
d.appendleft([ch,cw])
cost=[[-1 for i in range(w)]for j in range(h)]
dx=[1,0,-1,0,-2,-2,-2,-2,-2,-1,-1,-1,-1,0,0,1,1,1,1,2,2,2,2,2]
dy=[0,1,0,-1,-2,-1,0,1,2,-2,-1,1,2,-2,2,-2,-1,1,2,-2,-1,0,1,2]
for i in range(h):
    tizu.append(input())
cost[ch][cw]=0
while(d):
    x,y=d.popleft()
    for i in range(4):
        nx=x+dx[i]
        ny=y+dy[i]
        ####行ったことある、かつ、コストが手前より高い
        if(nx<0 or ny<0 or nx>=h or ny>=w):
            continue
        if(cost[nx][ny]>-1 and cost[nx][ny]<=cost[x][y]):
            continue
        if(tizu[nx][ny]=='.'):
            cost[nx][ny]=cost[x][y]
            d.appendleft([nx,ny])
    
    for i in range(4,24):
        nx=x+dx[i]
        ny=y+dy[i]
        if(nx<0 or ny<0 or nx>=h or ny>=w):
            continue
        if(cost[nx][ny]>-1):
            continue
        if(tizu[nx][ny]=='.'):
            cost[nx][ny]=cost[x][y]+1
            d.append([nx,ny])

print(cost[dh][dw])
### BUGGY CODE ###

def floyd_warshall(dist, graph):
    for i in range(N):
        dist[i][i] = 0
    
    for i in range(N):
        for j in range(i):
            dist[i][j] = dist[j][i] = graph[i][j]
        
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    
N, M, L = map(int, input().split())
graph = [[float('inf')] * N for _ in range(N)]

for _ in range(M):
    a, b, c = map(int, input().split())
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c

dist = [[float('inf')] * N for _ in range(N)]
floyd_warshall(dist, graph)

graph1 = [[float('inf')] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if dist[i][j] <= L:
            graph1[i][j] = 1
            
dist1 = [[float('inf')] * N for _ in range(N)]
floyd_warshall(dist1, graph1)

Q = int(input())
for _ in range(Q):
    start, end= map(int, input().split())
    if dist1[start-1][end-1] != float('inf'):
    	print(dist1[start-1][end-1] - 1)
    else:
        print(-1)


### FIXED CODE ###

N, M, L = map(int, input().split())
dist = [[10**12] * N for _ in range(N)]
for i in range(N):
    dist[i][i] = 0
    
for _ in range(M):
    a, b, c = map(int, input().split())
    if c <= L:
    	dist[a-1][b-1] = dist[b-1][a-1] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

old_dist = [row[:] for row in dist]
for i in range(N):
    for j in range(N):
        if old_dist[i][j] <= L:
            dist[i][j] = 1
            
for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

Q = int(input())
for _ in range(Q):
    start, end= map(int, input().split())
    if dist[start-1][end-1] < 10**12:
    	print(dist[start-1][end-1] - 1)
    else:
        print(-1)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
  b.append(a[i])
  b.reverse()
print(' '.join(map(str,b)))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
b = []
for i in range((n+1)//2):
  here = n-1-2*i
  b.append(str(a[here]))
for i in range(n//2):
  here = 2*i+(n%2)
  b.append(str(a[here]))
print(' '.join(b))
### BUGGY CODE ###

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

ans = 0

for i in range(n):
  ans += sum([A[i] + A[i + j] == j for j in range(1, n - i)])
  
print(ans)

### FIXED CODE ###

from collections import Counter

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

L = [i + a for i, a in enumerate(A)]
R = [i - a for i, a in enumerate(A)]

cL = Counter(L)
cR = Counter(R)

ans = 0
for i in cL.keys():
  ans += cL[i] * cR[i]

print(ans)
### BUGGY CODE ###

import heapq

N, M = map(int, input().split())
job_list = {}
ans = 0
kouho = []
for _ in range(N):
  A, B = map(int, input().split())
  B = B * (-1)
  if A in job_list.keys():
    job_list[A].append(B)
  else:
    job_list[A] = [B]

for day in range(1, M + 1):
  try: 
    kouho += job_list[day]
    heapq.heapify(kouho)
  except KeyError:
    pass
  if len(kouho) != 0:
    ans += heapq.heappop(kouho)

print(ans * (-1))

### FIXED CODE ###

import heapq

N, M = map(int, input().split())
AB_list = []
[heapq.heappush(AB_list, list(map(int, input().split()))) for _ in range(N)]
ans = 0
kouho = []

for day in range(1, M + 1):
    if len(AB_list) != 0:
        while AB_list[0][0] <= day:           
            heapq.heappush(kouho, heapq.heappop(AB_list)[1]*(-1))
            if len(AB_list) == 0:
                break
    if len(kouho) != 0:
        ans += heapq.heappop(kouho)

print(ans * (-1))
### BUGGY CODE ###

n = int(input())
s = input()
r_cnt = s.count("R")
g_cnt = s.count("G")
b_cnt = s.count("B")
ans = r_cnt * g_cnt * b_cnt

for i in range(n):
    for j in range(i + 1, n):
        k = j + (j - i)
        if k >= n:
            continue
        elif len(set([s[i], s[j], s[k]])) == 3:
            ans -= 1
print(ans)
            

### FIXED CODE ###

n = int(input())
s = input()
r_cnt = s.count("R")
g_cnt = s.count("G")
b_cnt = s.count("B")
ans = r_cnt * g_cnt * b_cnt

for i in range(n):
    for j in range(i + 1, n):
        k = j + (j - i)
        if k >= n:
            continue
        elif len(set([s[i], s[j], s[k]])) == 3:
            ans -= 1
print(ans)
### BUGGY CODE ###

S = list(input())
L = len(S)
K = int(input())
idx = 0
while K > 0:
    # aまでの必要な回数
    k = 123 - ord(S[idx])
    if k > K:
        if idx < L-1:
            # aまで操作できないのに、操作すると辞書順でより後ろの文字列になってしまうので、次の文字へ
            idx += 1
        else:
            # 一番後ろの場合
            t = chr(ord(S[idx])+(K%26))
            S[idx] = t
            K = 0
    else:
        if S[idx] != "a":
            K -= k
        S[idx] = "a"
        if idx < L-1:
            idx += 1

print("".join(S))


### FIXED CODE ###

S = list(input())
L = len(S)
K = int(input())
idx = 0
while K > 0:
    # aまでの必要な回数
    if S[idx] == "a" and idx < L-1:
        idx += 1
        continue
        
    k = 123 - ord(S[idx])
    if k > K:
        if idx < L-1:
            # aまで操作できないのに、操作すると辞書順でより後ろの文字列になってしまうので、次の文字へ
            idx += 1
        else:
            # 一番後ろの場合
            t = chr(ord(S[idx])+(K%26))
            S[idx] = t
            K = 0
    else:
        K -= k
        S[idx] = "a"
        if idx < L-1:
            idx += 1

print("".join(S))
### BUGGY CODE ###

n = int(input())
a = [int(i) for i in input().split()]
b = 1
for i in a:
    b *= i
c = 0
while b % 2 == 0:
    b //= 2
    c += 1
print(c)

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
b = 1
c = 0
for i in a:
    b = i
    while b % 2 == 0:
        b //= 2
        c += 1
print(c)
### BUGGY CODE ###

n,w=map(int,input().split())
dp=[{} for j in range(n+1)]
c,p=map(int,input().split())
dp[1][c]=p
for i in range(2,n+1):
  c,p=map(int,input().split())
  for j in dp[i-1].keys():
    if j+c<=w and dp[i-1][j] != 0:
      if j+c in dp[i-1]:
        dp[i][j+c]=max(dp[i-1][j+c],dp[i-1][j]+p)
      else:
        dp[i][j+c]=dp[i-1][j]+p
    if dp[i-1][j] != 0:
      dp[i][j]=dp[i-1][j]
  if c in dp[i-1]:
    dp[i][c]=max(dp[i-1][c],p)
  else:
    dp[i][c]=p
print(max([dp[n][i] for i in dp[n].keys()]))

### FIXED CODE ###

import sys
input=sys.stdin.readline
 
n,w=map(int,input().split())
dp=[0]*(w+1)
 
def ans(n,w):
  for _ in range(n):
    c,p=map(int,input().split())
    for j in range(w,c-1,-1):
      tmp=dp[j-c]+p
      if dp[j]<tmp:
        dp[j]=tmp
  return max(dp)
print(ans(n,w))
### BUGGY CODE ###

H, W, N = map(int, input().split())
A = []
for i in range(N):
  a, b = map(int, input().split())
  for j in range(3):
    for k in range(3):
      if (a - j > 0) and (a - j < H - 1) and (b - k > 0) and (b - k < W - 1):
        A.append([a - j, b - k])
A = sorted(sorted(A, key=lambda x: x[1]), key=lambda x: x[0])
A.append([0, 0])
prev = [0, 0]
count = 0
C = [0 for i in range(10)]
for a in A:
  if a == prev:
    count += 1
  else:
    C[count] += 1
    count = 1
  prev = a
print((H - 2) * (W - 2) - sum(C[1:]))
for c in C[1:]:
  print(c)

### FIXED CODE ###

from collections import defaultdict
H, W, N = map(int, input().split())
P = [0] * 10
P[0] = (H - 2) * (W - 2)
G = defaultdict(lambda: defaultdict(int))
for i in range(N):
  a, b = map(int, input().split())
  for i in range(max(a - 3, 0), min(a, H - 2)):
    for j in range(max(b - 3, 0), min(b, W - 2)):
      p = G[i][j]
      P[p] -= 1
      P[p + 1] += 1
      G[i][j] += 1
for i in range(10):
  print(P[i])
### BUGGY CODE ###

#!/usr/bin/env python3
# 最初はごちゃごちゃ考えていたが、文字列を１文字ずつリストにしてからソートして
# それをさらに文字列に戻してソートしたらおわり
n = int(input())
sort = [""]*n
for i in range(n):
    s = list(input())
    s.sort()
    sort[i] = str(s)
sort.sort()
#print(sort)
ans = 0
cnt = 0
for i in range(n-1):
    if sort[i+1] == sort[i]: cnt += 1
    else: 
        ans += cnt*(cnt+1)//2
        cnt = 0
print(ans+cnt*(cnt+1)//2)


### FIXED CODE ###

#!/usr/bin/env python3
# 最初はごちゃごちゃ考えていたが、文字列を１文字ずつリストにしてからソートして
# それをさらに文字列に戻してソートしたらおわり
n = int(input())
sort = [""]*n
for i in range(n):
    s = list(input())
    s.sort()
    sort[i] = s
sort.sort()
#print(sort)
ans = 0
cnt = 0
for i in range(n-1):
    if sort[i+1] == sort[i]: cnt += 1
    else: 
        ans += cnt*(cnt+1)//2
        cnt = 0
print(ans+cnt*(cnt+1)//2)
### BUGGY CODE ###

n = int(input())
a = map(str, input().split())
a = " ".join(a)

m = int(input())
for i in range(m):
               b, c = map(str,input().split())
               #ans = sum([int(i) for i in a])
               a=a.replace(b,c).replace(" ","+")
               
               print(eval(a))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
m = int(input())
t = [0] * (10 ** 5 + 1)
ans = sum(a)
for i in a:
    t[i] += 1
for i in range(m):
               b, c = map(int,input().split())
               #ans = sum([int(i) for i in a])
               ans -= b * t[b]
               ans += c * t[b]
               t[c] += t[b]
               t[b] = 0
               #ans = ans - a.count("b")(int("c")-int("b"))
               print(ans)
### BUGGY CODE ###

N, K = list(map(int, input().split()))
if N >= K:
  ans = N
  for i in range(int(N/K)):
    ans = ans - K
  print(min(ans, max(ans-K, K-ans)))
else:
  print(min(N, max(N-K, K-N)))

### FIXED CODE ###

N, K = list(map(int, input().split()))
if N >= K:
  N = N % K
print(min(N, max(N-K, K-N)))
### BUGGY CODE ###


N = int(input())
A = input().split()
for i in range(N):
    A[i] = int(A[i])

S = []
for i in range(N):
    B = A.index(max(A))
    A[A.index(max(A))] -= 100000
    S.append(B+1)


for i in reversed(range(0,N)):
    print(str(S[i]) + " ")

### FIXED CODE ###

N = int(input())
L = list(map(int, input().split()))

M = []

for i in range(len(L)):
    l = (L[i], i+1)
    M.append(l)

M = sorted(M)

for x in M:
    print(x[1])
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N = int(input())
H = [int(item) for item in input().split()]

cand = []
cand += [H[0], H[0] - 1]
for i in range(1, N):
    new_cand = []
    for c in cand:
        if c <= H[i] - 1:
            new_cand += [H[i], H[i] - 1]
        elif c == H[i]:
            new_cand += [H[i]]
    cand = new_cand
    if len(cand) == 0:
        print("No")
        break
else:
    print("Yes")


### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input())
H = [int(item) for item in input().split()]

cand = []
cand += [H[0], H[0] - 1]
for i in range(1, N):
    new_cand = []
    for c in cand:
        if c <= H[i] - 1:
            new_cand += [H[i], H[i] - 1]
        elif c == H[i]:
            new_cand += [H[i]]
    cand = list(set(new_cand))
    if len(cand) == 0:
        print("No")
        break
else:
    print("Yes")
### BUGGY CODE ###

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)]
INF = 10**12

def binary_search(query, arr):
    arr = [-INF] + arr + [INF]
    low = 0
    high = len(arr)
    while high-low>1:
        mid = (low+high)//2
        if query>arr[mid]:
            low = mid
        else:
            high = mid
    return arr[low], arr[high]

def main():
    for x in X:
        s1, s2 = binary_search(x, S)
        t1, t2 = binary_search(x, T)
        ans = INF
        ans = [ min(ans, abs(t-s)+min(abs(t-x), abs(s-x)))\
            for t in [t1, t2] for s in [s1, s2] ]
        print(min(ans))
    return

main()

### FIXED CODE ###

A, B, Q = map(int, input().split())
INF = 10**12
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)]


def binary_search(query, arr):
    low = 0
    high = len(arr)
    while high-low>1:
        mid = (low+high)//2
        if query>arr[mid]:
            low = mid
        else:
            high = mid
    return arr[low], arr[high]

def main():
    for x in X:
        s1, s2 = binary_search(x, S)
        t1, t2 = binary_search(x, T)
        ans = [ abs(t-s)+min(abs(t-x), abs(s-x)) \
            for t in [t1, t2] for s in [s1, s2] ]
        print(min(ans))
    return

main()
### BUGGY CODE ###

# number of balls
N = input()
# ball values
K = list(map(int, input().split()))

# get ball counts
ball_counts = {}
for i in range(len(K)):
    ball_value = K[i]
    if ball_value in ball_counts:
        ball_counts[ball_value] += 1
    else:
        ball_counts[ball_value] = 1

for i in range(len(K)):
    ball_value = K[i]
    two_equal_values_count = 0
    for value, count in ball_counts.items():
        # check if we can even come up with a pair
        if count > 1:
            if value == ball_value:
                # if we have three balls [1, 1, 1] and the current ball is 1, we want to remove our current 1 and only look at [1, 1]
                two_equal_values_count += (count - 1) * (count - 2) / 2
            else:
                two_equal_values_count += count * (count - 1) / 2

    print(int(two_equal_values_count))

### FIXED CODE ###

# number of balls
N = input()
# ball values
K = list(map(int, input().split()))

# get ball counts
# ball_counts = {}
# for i in range(len(K)):
#     ball_value = K[i]
#     if ball_value in ball_counts:
#         ball_counts[ball_value] += 1
#     else:
#         ball_counts[ball_value] = 1

# for i in range(len(K)):
#     ball_value = K[i]
#     two_equal_values_count = 0
#     for value, count in ball_counts.items():
#         # check if we can even come up with a pair
#         if count > 1:
#             if value == ball_value:
#                 # if we have three balls [1, 1, 1] and the current ball is 1, we want to remove our current 1 and only look at [1, 1]
#                 two_equal_values_count += (count - 1) * (count - 2) / 2
#             else:
#                 two_equal_values_count += count * (count - 1) / 2

# get ball counts
ball_counts = {}
for i in range(len(K)):
    ball_value = K[i]
    if ball_value in ball_counts:
        ball_counts[ball_value] += 1
    else:
        ball_counts[ball_value] = 1

# get sums
total_sum = 0
for value, count in ball_counts.items():
    total_sum += (count * (count - 1)) / 2

# remove extra
for i in range(len(K)):
    ball_value = K[i]
    print(int(total_sum - (ball_counts[ball_value] - 1)))