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

from numba import njit
from numba.typed import List


def comb(li):
    return len(li) * (len(li) - 1) // 2


@njit
def count_large(x, li):
    cnt = 0
    j = 0
    for e in li:
        cnt -= e * e >= x
        while li[j-1] * e >= x:
            j -= 1

        cnt -= j

    cnt //= 2
    return cnt


n, k = map(int, input().split())
a = list(map(int, input().split()))
INF = 10 ** 20

neg = []
pos = []

for e in a:
    if e > 0:
        pos.append(e)
    elif e < 0:
        neg.append(e)

# k-th is negative
if k <= len(pos) * len(neg):
    neg.sort()
    neg.append(0)
    pos.sort()

    lb = -10 ** 18 - 1
    ub = 0
    while ub - lb > 1:
        m = (lb + ub) // 2
        j = -1
        cnt = 0
        for e in pos:
            while neg[j+1] * e <= m:
                j += 1

            cnt += j + 1

        if cnt >= k:
            ub = m
        else:
            lb = m

    print(ub)

# k-th is positive
elif k >= n * (n - 1) // 2 - comb(pos) - comb(neg) + 1:
    neg = [-e for e in neg]
    neg.append(0)
    neg.sort()
    pos.append(0)
    pos.sort()
    neg2 = List()
    [neg2.append(e) for e in neg]
    pos2 = List()
    [pos2.append(e) for e in pos]


    lb = 1
    ub = 10 ** 18 + 1
    while ub - lb > 1:
        m = (lb + ub) // 2
        cnt = count_large(m, neg2) + count_large(m, pos2)
        if cnt >= n * (n - 1) // 2 - k + 1:
            lb = m
        else:
            ub = m

    print(lb)


# k-th is 0
else:
    print(0)


### FIXED CODE ###

def comb(li):
    return len(li) * (len(li) - 1) // 2


def count_large(x, li):
    cnt = 0
    j = 0
    for e in li:
        cnt -= e * e >= x
        while li[j-1] * e >= x:
            j -= 1

        cnt -= j

    cnt //= 2
    return cnt


n, k = map(int, input().split())
a = list(map(int, input().split()))
INF = 10 ** 20

neg = []
pos = []

for e in a:
    if e > 0:
        pos.append(e)
    elif e < 0:
        neg.append(e)

# k-th is negative
if k <= len(pos) * len(neg):
    neg.sort()
    neg.append(0)
    pos.sort()

    lb = -10 ** 18 - 1
    ub = 0
    while ub - lb > 1:
        m = (lb + ub) // 2
        j = -1
        cnt = 0
        for e in pos:
            while neg[j+1] * e <= m:
                j += 1

            cnt += j + 1

        if cnt >= k:
            ub = m
        else:
            lb = m

    print(ub)

# k-th is positive
elif k >= n * (n - 1) // 2 - comb(pos) - comb(neg) + 1:
    neg = [-e for e in neg]
    neg.append(0)
    neg.sort()
    pos.append(0)
    pos.sort()

    lb = 1
    ub = 10 ** 18 + 1
    while ub - lb > 1:
        m = (lb + ub) // 2
        cnt = count_large(m, neg) + count_large(m, pos)
        if cnt >= n * (n - 1) // 2 - k + 1:
            lb = m
        else:
            ub = m

    print(lb)


# k-th is 0
else:
    print(0)
### BUGGY CODE ###

from collections import Counter
N = int(input())
l = [''.join(sorted(list(input())))]
cnt = 0
for i in range(N-1):
    s = ''.join(sorted(list(input())))
    cnt += l.count(s)
    l.append(s)
print(cnt)

### FIXED CODE ###

import collections
from itertools import combinations
import sys
input = sys.stdin.readline

N = int(input())
s = [''.join(sorted(list(input()))) for _ in range(N)]
c = collections.Counter(s)

cnt = 0
for i in c.values():
    if i > 1:
        cnt += i*(i-1)//2
print(cnt)
### BUGGY CODE ###

N = int(input())
total = 0
for i in range(1, N):
  total += i
  
print(total)


### FIXED CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
total = sum(range(1, N))
  
print(total)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
from collections import deque
sys.setrecursionlimit(10**6)

def main():
    n,m=map(int,input().split())
    graph=[[] for _ in range(n)]
    seen=[False]*n

    for _ in range(m):
        a,b=map(int,input().split())
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)
    ans=[-1]*n
    q=deque([0])
    while len(q):
        now=q.popleft()
        seen[now]=True
        for i in graph[now]:
            if seen[i]:
                continue
            q.append(i)
            if ans[i]==-1:
                ans[i]=now
    print("Yes")
    for i in range(1,n):
        print(ans[i]+1)

if __name__=="__main__":
    main()

### FIXED CODE ###

import sys
input=sys.stdin.readline
from collections import deque
sys.setrecursionlimit(10**6)

def main():
    n,m=map(int,input().split())
    graph=[[] for _ in range(n)]
    seen=[False]*n

    for _ in range(m):
        a,b=map(int,input().split())
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)
    ans=[-1]*n
    q=deque([0])
    seen[0]=True
    while len(q):
        now=q.popleft()
        for i in graph[now]:
            if seen[i]:
                continue
            seen[i]=True
            q.append(i)
            if ans[i]==-1:
                ans[i]=now
    print("Yes")
    for i in range(1,n):
        print(ans[i]+1)

if __name__=="__main__":
    main()
### BUGGY CODE ###

K=int(input())
i='7'
if K%2==0 or K%5==0:
    print('-1')
else:
    for d in range(K):
        if int(i)%K==0:
            print(len(str(i)))
            break
        else:
            i+='7'

### FIXED CODE ###


K=int(input())
i=0
if K%2==0 or K%5==0:
    print('-1')

else:
    for d in range(K):
        i=(10*i+7)%K
        if i==0:
            print(d+1)
            break
### BUGGY CODE ###

H, W = map(int, input().split())
X = [[[0, 1][a=="#"] for a in input()] for i in range(H)]
def countRD(n, i, j):
    return ccc(n, i, j, 1, 1)
def countRU(n, i, j):
    return ccc(n, i, j, -1, 1)
def countLD(n, i, j):
    return ccc(n, i, j, 1, -1)
def countLU(n, i, j):
    return ccc(n, i, j, -1, -1)
def countR(n, i, j):
    return cc(n, i, j, 0, 1)
def countL(n, i, j):
    return cc(n, i, j, 0, -1)
def countD(n, i, j):
    return cc(n, i, j, 1, 0)
def countU(n, i, j):
    return cc(n, i, j, -1, 0)
def ccc(n, i, j, DU, RL):
    c = 0
    for k in range(1, n):
        if i+k*DU >= 0 and i+k*DU < H:
            if j+(n-k)*RL >= 0 and j+(n-k)*RL < W:
                c += X[i+k*DU][j+(n-k)*RL]
    return c
def cc(n, i, j, DU, RL):
    ret = 0
    if i+n*DU >= 0 and i+n*DU < H:
        if j+n*RL >= 0 and j+n*RL < W:
            ret = X[i+n*DU][j+n*RL]
    return ret

ans = 0
for i in range(H):
    for j in range(W):
        for n in range(1, min(max(i+j,H-i+W-j), max(i+W-j,H-i+j))+2):
            if countR(n, i, j) and countD(n, i, j):
                ans += countLU(n, i, j)
            if countR(n, i, j) and countU(n, i, j):
                ans += countLD(n, i, j)
            if countL(n, i, j) and countD(n, i, j):
                ans += countRU(n, i, j)
            if countL(n, i, j) and countU(n, i, j):
                ans += countRD(n, i, j)
            if countR(n, i, j) and countD(n, i, j) and countL(n, i, j):
                ans += 1
            if countR(n, i, j) and countD(n, i, j) and countU(n, i, j):
                ans += 1
            if countR(n, i, j) and countU(n, i, j) and countL(n, i, j):
                ans += 1
            if countD(n, i, j) and countU(n, i, j) and countL(n, i, j):
                ans += 1
            
            
print (ans)





### FIXED CODE ###

H, W = map(int, input().split())
I = [input() for _ in range(H)]
X = [[[0, 1][a=="#"] for a in inp] for inp in I]
k = 32
def r():
    global H, W, I
    I = ["".join([I[H - 1 - j][i] for j in range(H)]) for i in range(W)]
    H, W = W, H
def st1(s):
    return int(s.replace("#", "1" * k).replace(".", "0" * k), 2)
def st2(s):
    return int(s.replace("#", "0" * (k - 1) + "1").replace(".", "0" * k), 2)
def getsum(x):
    for i in range(8):
        x += x >> (k << i)
    return x & ((1 << k) - 1)

ans = 0
for _ in range(4):
    A1 = [st1(inp) for inp in I]
    A2 = [st1("".join([I[i][j] for i in range(H)])) for j in range(W)]
    B = [st2(inp[::-1]) for i, inp in enumerate(I)]
    C = [[0] * W for _ in range(H)]
    for j in range(W):
        s = 0
        m = (1 << j * k) - 1
        for i in range(H)[::-1]:
            s <<= k
            s += B[i] >> (j+1) * k
            s &= m
            C[i][j] = s
    for i in range(1, H):
        for j in range(1, W):
            ans += A1[i] >> (W - j) * k & A2[j] >> (H - i) * k & C[i][j]
    r()
            
print(getsum(ans))
### BUGGY CODE ###

n=int(input())
a=list(map(int, input().split()))
import collections
import math
def combinations_count2(n):
    if(n<=1):
        answer=0
    else:
        answer=n*(n-1)/2
    return answer

table=collections.Counter(a)
keytable=table.keys()
c=[]

for key in keytable:
    c.append(table[key])
#print(c)
ca=[]
for j in range(len(c)):
    ca.append(combinations_count2(c[j]))
#print(ca)
sums=sum(ca)
#print(sum)
#print(keytable)
#print(table)
for i in range(len(a)):
    keynum=list(keytable).index(a[i])
    answer=sums-ca[keynum]+combinations_count2(c[keynum]-1)
    print(int(answer))

### FIXED CODE ###

n=int(input())
a=list(map(int, input().split()))
import collections
import math
def combinations_count2(n):
    if(n<=1):
        answer=0
    else:
        answer=n*(n-1)/2
    return answer

table=collections.Counter(a)
keytable=table.keys()
sums=0
for value in table.values():
    sums+=combinations_count2(value)
#print(ca)
#print(sum)
#print(keytable)
#print(table)
for i in range(len(a)):
    answer=sums-table[a[i]]+1
    print(int(answer))
### BUGGY CODE ###

import sys
import numpy as np
import math
import copy
input = sys.stdin.readline
 
N = int(input())
A = np.array(list(map(int,input().split())))
r = np.array(list(range(1,N+1)))
B = np.array(sorted(A-r))
bmin = B[N//4]
bmax = B[N*3//4]
ans = float('inf')
for bi in range(bmin,bmax+1):
    ans = min(ans,sum(list(map(abs,B - bi))))
print(ans)

### FIXED CODE ###

import sys
import numpy as np
import math
import copy
input = sys.stdin.readline
 
N = int(input())
A = np.array(list(map(int,input().split())))
if N ==1:
    ans = 0
else:
    r = np.array(list(range(1,N+1)))
    B = np.array(sorted(A-r))
    ans = float('inf')
    for i in range(max(N//2-1,0),min(N//2+2,N)):
        c = list(map(abs,(B - B[i])))
        ans = min(ans,sum(c))
print(ans)
### BUGGY CODE ###

import bisect
N=int(input())
P=list(map(int,input().split()))

pos=[-1]*(N+1)

for i in range(N):
  pos[P[i]]=i
  
called=[-1,-1,pos[N],N,N]
ans=0
for i in range(N-1,0,-1):
  hoge=pos[i]
  r=bisect.bisect_left(called,hoge)
  R=called[r]
  RR=called[r+1]
  L=called[r-1]
  LL=called[r-2]
  ans+=i*((RR-R)*(hoge-L)+(L-LL)*(R-hoge))
  called=called[:r]+[hoge]+called[r:]
print(ans)
  


### FIXED CODE ###

import bisect
N=int(input())
P=list(map(int,input().split()))

pos=[-1]*(N+1)

for i in range(N):
  pos[P[i]]=i
  
called=[-1,-1,pos[N],N,N]
ans=0
for i in range(N-1,0,-1):
  hoge=pos[i]
  r=bisect.bisect_left(called,hoge)
  R=called[r]
  RR=called[r+1]
  L=called[r-1]
  LL=called[r-2]
  ans+=i*((RR-R)*(hoge-L)+(L-LL)*(R-hoge))
  called.insert(r,hoge)
  #called=called[:r]+[hoge]+called[r:]
print(ans)
### BUGGY CODE ###

def main():
    import sys
    import numpy as np
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    N, S = [int(x) for x in input().strip().split()]
    An = [int(x) for x in input().strip().split()]
    dp = np.zeros((2, S+1), dtype=int)
    dp[0, 0] = 2
    if An[0] <= S:
        dp[0, An[0]] = 1

    for n in range(1, N):
        dp[(n)%2, :] *= 0
        for k in range(S, -1, -1):
            dp[n%2, k] = (dp[n%2, k] + dp[(n-1)%2, k] * 2) % 998244353
            if k + An[n] > S:
                continue
            dp[n%2, k+An[n]] = (dp[n%2, k+An[n]] + dp[(n-1)%2, k]) % 998244353

    print(dp[(N-1)%2, S])
                
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    import numpy as np
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    N, S = [int(x) for x in input().strip().split()]
    An = [int(x) for x in input().strip().split()]
    dp = np.zeros((S+1), dtype=int)
    dp[0] = 2
    if An[0] <= S:
        dp[An[0]] = 1

    for n in range(1, N):
        dp *= 2
        dp[An[n]:] += dp[:-An[n]] // 2
        dp %= 998244353

    print(dp[S])
                
if __name__ == '__main__':
    main()
### BUGGY CODE ###

### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    binArr = [[False for i in range(60)] for j in range(n)]
    cnt=[0]*60
    for i in range(n):
        b = bin(arr[i])[2:]
        lenb = len(b)
        for j in range(lenb):
            if int(b[lenb-1-j])==1:
                binArr[i][j] = True
                cnt[j]+=1
    ans=[0]*60
    answer = 0
    for i in range(n):
        for j in range(60):
            # 1: cnt[j]
            # 0: n-cnt[j]
            cnt[j]-=binArr[i][j]
            if binArr[i][j] == False:
                ans[j] += cnt[j]
            else:
                ans[j] += (n-cnt[j]-i-1)
    x=1
    for i in range(60):
        answer += ans[i]*x
        answer %= mod
        x*=2
        x%=mod
    print(answer)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

### FIXED CODE ###

### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    binArr = [[0 for i in range(60)] for j in range(n)]
    cnt=[0]*60
    for i in range(n):
        b = bin(arr[i])[2:]
        lenb = len(b)
        for j in range(lenb):
            binArr[i][j] = int(b[lenb-1-j])
            cnt[j]+=binArr[i][j]
    ans=[0]*60
    answer = 0
    for i in range(n):
        for j in range(60):
            # 1: cnt[j]
            # 0: n-cnt[j]
            cnt[j]-=binArr[i][j]
            if binArr[i][j] == 0:
                ans[j] += cnt[j]
            else:
                ans[j] += (n-cnt[j]-i-1)
    x=1
    for i in range(60):
        answer += ans[i]*x
        answer %= mod
        x*=2
        x%=mod
    print(answer)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n,q = map(int,input().split())
tree = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    tree[a]+=[b]
    tree[b]+=[a]

ans = [0 for i in range(n)]
for i in range(q):
    p,x = map(int,input().split())
    p -= 1
    ans[p] += x

#入力

def dfs(pre,now,w):
    ans[now] += w
    for i in tree[now]:
        if i != pre:
            dfs(now,i,ans[now])

dfs(-1,0,0)

print(*ans)

### FIXED CODE ###

n,q = map(int,input().split())
tree = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    tree[a].append(b)

ans = [0 for i in range(n)]
for i in range(q):
    p,x = map(int,input().split())
    p -= 1
    ans[p] += x

#入力

stack = [0]
while len(stack) > 0:
    now = stack.pop()
    for i in tree[now]:
        ans[i] += ans[now]
        stack.append(i)

for i in range(n):
    print(ans[i],end=" ")
print()
### BUGGY CODE ###

def multmod(a,b,m):
  ans = 0
  a = a % m
  
  while b:
    if (b & 1): # odd
      ans = (ans + a) % m
    
    a = (2 * a) % m
    b >>= 1 # b = b / 2
    
  return ans


n = int(input())
S = [int(a) for a in input().split()]
divisor = 10**9 + 7
tot = 0
for i in range(n-1):
  for j in range(i+1,n):
    
    tot += multmod(S[i],S[j],divisor)
    if tot >= divisor:
      tot = tot % divisor
    
print(tot)

### FIXED CODE ###

def multmod(a,b,m):
  ans = 0
  a = a % m
  
  while b:
    if (b & 1): # odd
      ans = (ans + a) % m
    
    a = (2 * a) % m
    b >>= 1 # b = b / 2
    
  return ans

n = int(input())
S = [int(a) for a in input().split()]
divisor = 10**9 + 7
tot = 0
a,b = 0,0
arr_sum = sum(S) #% divisor
arr_ssq = arr_sum*arr_sum #% divisor
isq_sum = 0
for i in range(n):
  isq_sum += S[i]*S[i] #% divisor
  
#isq_sum = isq_sum % divisor
tot = (arr_ssq - isq_sum)//2 % divisor

print(tot)
### BUGGY CODE ###

s = input()
q = int(input())

t = 0
for i in range(q):
    query = input()
    if query == '1':
        if t == 1:
            t = 0
        else:
            t = 1
    else:
        if query[2] == '1':
            if t == 0:
                s = query[4]+s
            else:
                s = s+query[4]
        else:
            if t == 0:
                s = s+query[4]
            else:
                s = query[4] + s

if t == 1:
    print(s[::-1])
else:
    print(s)

### FIXED CODE ###

s = input()
q = int(input())

t = 0
l = ''
r = ''
for i in range(q):
    query = input()
    if query == '1':
        if t == 1:
            t = 0
        else:
            t = 1
    else:
        if query[2] == '1':
            if t == 0:
                l = query[4:]+l
            else:
                r = r+query[4]
        else:
            if t == 0:
                r = r+query[4]
            else:
                l = query[4] + l
s = l+s+r
if t == 1:
    print(s[::-1])
else:
    print(s)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
l = []
r = []
for i in range(n):
    l.append(a[i]+(i+1))
    r.append((i+1)-a[i])
ans = 0
for i in l:
    for j in r:
        if i == j:
            ans += 1
print(ans)

### FIXED CODE ###

# 参考 : https://atcoder.jp/contests/abc166/submissions/16829140
n = int(input())
a = list(map(int,input().split()))
# 参加者 i,j が取引する場合、 j - i = A_i + A_j が成り立つ。
# 変形すると -i - A_i = -j + A_j, i + A_i = j - A_j になる。
# l = i + A_i, r = j - A_j
l = [i + a[i] for i in range(n)]
r = [i - a[i] for i in range(n)]
# 連想配列(辞書)を使う。
x = {}
y = {}
# 辞書にキーを追加する。
for i in range(n):
    x[l[i]] = 0
    y[l[i]] = 0
    y[r[i]] = 0
# キーの値を人数分増やす。
for i in range(n):
    x[l[i]] += 1
    y[r[i]] += 1
ans = 0
# x のキーで取引する人数を調べる。
for i in set(x.keys()):
    ans += x[i] * y[i]
print(ans)
### BUGGY CODE ###

import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    P = LI()

    s = [[0] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            s[i][j] = min(i,N-1-i,j,N-1-j)

    r = [[1] * N for _ in range(N)]

    ans = 0
    q = []
    for p in P:
        x = (p-1)//N
        y = (p-1) % N
        ans += s[x][y]
        r[x][y] = 0
        q.append((x,y))
        while q:
            a,b = q.pop()
            nc = s[a][b] + r[a][b]
            for da,db in ((1,0),(0,1),(-1,0),(0,-1)):
                na = a + da; nb = b + db
                if 0 < na < N-1 and 0 < nb < N-1:
                    if s[na][nb] <= nc: continue
                    s[na][nb] = nc
                    q.append((na,nb))
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    P = LI()

    s = []
    for i in range(N):
        for j in range(N):
            s.append(min(i,N-1-i,j,N-1-j))

    r = [1] * (N*N)

    ans = 0
    q = []
    for p in P:
        p -= 1
        ans += s[p]
        r[p] = 0
        q.append(p)
        while q:
            a = q.pop()
            nc = s[a] + r[a]

            if a >= N:
                if s[a-N] > nc:
                    s[a-N] = nc
                    q.append(a-N)
            if a + N < N*N:
                if s[a+N] > nc:
                    s[a+N] = nc
                    q.append(a+N)
            if a % N:
                if s[a-1] > nc:
                    s[a-1] = nc
                    q.append(a-1)
            if a % N < N -1:
                if s[a+1] > nc:
                    s[a+1] = nc
                    q.append(a+1)

    print(ans)

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

# coding: utf-8
# Your code here!

from collections import deque

N = int(input())
H = deque(list(map(int, input().split())))
tmp = 0

for i in range(N):
    tmp = H.popleft()
    if H == deque([]):
        print("Yes")
        exit()
    elif tmp - 1 > min(set(H)):
        print("No")
        exit()
    else:
        if tmp - 1 > H[0]:
            print("No")
            exit()
        elif tmp > H[0]:
            if len(H) == 1:
                print("Yes")
                exit()
            elif H[0] > H[1]:
                print("No")
                exit()

### FIXED CODE ###

# coding: utf-8
# Your code here!

from collections import deque

N = int(input())
H = deque(list(map(int, input().split())))
tmp = 0
max_num = 0

for i in range(N):
    tmp = H.popleft()
    if H == deque([]):
        print("Yes")
        exit()
    else:
        if tmp - 1 > H[0]:
            print("No")
            exit()
        elif max_num - 1 > tmp:
            print("No")
            exit()
        elif tmp > H[0]:
            if len(H) == 1:
                print("Yes")
                exit()
            elif H[0] > H[1]:
                print("No")
                exit()
        if max_num < tmp:
            max_num = tmp
### BUGGY CODE ###

inf = 1 << 60
A,B,Q = map(int,input().split())
s = []
t = []
x = []
s.append(-inf*2)
s.append(-inf)
t.append(-inf*2)
t.append(-inf)
for i in range(A):
    s.append(int(input()))
for i in range(B):
    t.append(int(input()))
for i in range(Q):
    x.append(int(input()))
s.append(inf)
s.append(inf*2)
t.append(inf)
t.append(inf*2)

def search(lst, target):
    min1 = 0
    max1 = len(lst)
    while max1 - min1 > 1:
        mid1 = (min1 + max1) // 2
        if lst[mid1] <= target:
            min1 = mid1
        else:
            max1 = mid1
    return min1

def solve(x):
    chk = [0] * 8
    s1 = search(s, x)

    chk[0] = abs(s[s1] - x)
    chk[1] = abs(s[s1] - x)
    chk[2] = abs(s[s1+1] - x)
    chk[3] = abs(s[s1+1] - x)

    t1 = search(t, s[s1])
    t2 = search(t, s[s1+1])
    chk[0] += abs(t[t1] - s[s1])
    chk[1] += abs(t[t1+1] - s[s1])
    chk[2] += abs(t[t2] - s[s1+1])
    chk[3] += abs(t[t2+1] - s[s1+1])

    t1 = search(t, x)

    chk[4] = abs(t[t1] - x)
    chk[5] = abs(t[t1] - x)
    chk[6] = abs(t[t1+1] - x)
    chk[7] = abs(t[t1+1] - x)

    s1 = search(s, t[t1])
    s2 = search(s, t[t1+1])
    chk[4] += abs(s[s1] - t[t1])
    chk[5] += abs(s[s1+1] - t[t1])
    chk[6] += abs(s[s2] - t[t1+1])
    chk[7] += abs(s[s2+1] - t[t1+1])

    return min(chk)

for xi in x:
    ans = solve(xi)
    print(ans)


### FIXED CODE ###

inf = 1 << 60
A,B,Q = map(int,input().split())
s = []
t = []
x = []
s.append(-inf*2)
s.append(-inf)
t.append(-inf*2)
t.append(-inf)
for i in range(A):
    s.append(int(input()))
for i in range(B):
    t.append(int(input()))
for i in range(Q):
    x.append(int(input()))
s.append(inf)
s.append(inf*2)
t.append(inf)
t.append(inf*2)

def search(lst, target):
    min1 = 0
    max1 = len(lst)
    while max1 - min1 > 1:
        mid1 = (min1 + max1) // 2
        if lst[mid1] <= target:
            min1 = mid1
        else:
            max1 = mid1
    return min1

def solve(x):
    chk = [0] * 8
    s1 = search(s, x)

    chk[0] = abs(s[s1] - x)
    chk[1] = abs(s[s1] - x)
    chk[2] = abs(s[s1+1] - x)
    chk[3] = abs(s[s1+1] - x)

    t1 = search(t, s[s1])
    t2 = search(t, s[s1+1])
    chk[0] += abs(t[t1] - s[s1])
    chk[1] += abs(t[t1+1] - s[s1])
    chk[2] += abs(t[t2] - s[s1+1])
    chk[3] += abs(t[t2+1] - s[s1+1])

    t1 = search(t, x)

    chk[4] = abs(t[t1] - x)
    chk[5] = abs(t[t1] - x)
    chk[6] = abs(t[t1+1] - x)
    chk[7] = abs(t[t1+1] - x)

    s1 = search(s, t[t1])
    s2 = search(s, t[t1+1])
    chk[4] += abs(s[s1] - t[t1])
    chk[5] += abs(s[s1+1] - t[t1])
    chk[6] += abs(s[s2] - t[t1+1])
    chk[7] += abs(s[s2+1] - t[t1+1])

    return min(chk)

for xi in x:
    ans = solve(xi)
    print(ans)