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

import math

def resolve():
    MOD = 10**9 + 7
    N, K = map(int, input().split())
    A = map(int, input().split())

    A = sorted(A)

    def permutations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    sum = 0
    for i in range(K-1, N):
        sum += permutations_count(i, K-1) * A[i] % MOD
        #print(sum)

    A = sorted(A, reverse=True)

    for i in range(K-1, N):
        sum -= permutations_count(i, K-1) * A[i] % MOD
        #print(sum)

    print(sum % MOD)


if __name__ == "__main__":
    resolve()

### FIXED CODE ###

import math
from functools import lru_cache
from operator import mul
from functools import reduce


def resolve():
    import sys
    input = sys.stdin.readline
    MOD = 10**9 + 7
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    A.sort()
    B = A[::-1]

    @lru_cache(maxsize=None)
    def combinations_count__(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    @lru_cache(maxsize=None)
    def combinations_count____(n, r):
        r = min(r, n - r)
        numer = reduce(mul, range(n, n - r, -1), 1)
        denom = reduce(mul, range(1, r + 1), 1)
        return numer // denom

    def combinations_count_(n, r):
        if n - r < r: r = n - r
        if r == 0: return 1
        if r == 1: return n

        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]

        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot

        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])

        return result

    def modinv(a, mod=10**9+7):
        return pow(a, mod-2, mod)

    def combinations_count(n, r, mod=10**9+7):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n-r)
        return fact[n] * factinv[r] * factinv[n-r] % mod
    
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)

    sum = 0
    for i in range(K-1, N):
        sum += combinations_count(i, K-1) * A[i] % MOD - combinations_count(i, K-1) * B[i] % MOD

    print(sum % MOD)


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

# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math

n, k = map(int, input().split())
a = list(map(int, input().split()))
# n = int(input())
mod = 10 ** 9 + 7
p = mod
a.sort(reverse = True)
# print(a)
ans = 0


def C(n, k):
    if k == 0:
        return 1
    elif n < k or k < 0:
        return 0
    else:
        x,y = 1,1
        while k > 0 and n > 0:
            x *= n
            y *= k
            n, k = n-1, k-1

        return x * pow(y, mod-2, mod) % mod


# fac = [0] * (n + 1)
# fac[0] = 1
# for i in range(n):
#     fac[i + 1] = fac[i] * (i + 1) % mod
# 
# def C(n, k):
#     if n == 0 and k == 0:
#         return 1
#     if n < k or k < 0:
#         return 0
#     return fac[n] * pow(fac[n - k], p - 2, p) * pow(fac[k], p - 2, p) % p
# 

for i in range(0,n-k+1):
    ans += a[i] * C(n-i-1, k-1)
    ans %= mod

a.reverse()
for i in range(0,n-k+1):
    ans -= a[i] * C(n-i-1, k-1)
    ans %= mod



print(ans)


### FIXED CODE ###

# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math

n, k = map(int, input().split())
a = list(map(int, input().split()))
# n = int(input())
mod = 10 ** 9 + 7
p = mod
a.sort(reverse = True)
# print(a)
ans = 0

#
# def C(n, k):
#     if k == 0:
#         return 1
#     elif n < k or k < 0:
#         return 0
#     else:
#         x,y = 1,1
#         while k > 0:
#             x *= n
#             y *= k
#             n, k = n-1, k-1
#
#         return x * pow(y, mod-2, mod) % mod
#

fac = [0] * (n + 1)
fac[0] = 1
for i in range(n):
    fac[i + 1] = fac[i] * (i + 1) % mod


def C(n, k):
    if n == 0 and k == 0:
        return 1
    if n < k or k < 0:
        return 0
    return fac[n] * pow(fac[n - k], p - 2, p) * pow(fac[k], p - 2, p) % p


for i in range(0,n-k+1):
    ans += a[i] * C(n-i-1, k-1)
    ans %= mod

a.reverse()
for i in range(0,n-k+1):
    ans -= a[i] * C(n-i-1, k-1)
    ans %= mod



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

N = int(input())

count = 0

for i in range(N+1):
 
    thr = str(i).count("3")
    fiv = str(i).count("5")
    sev = str(i).count("7")


    if thr > 0 and fiv > 0 and sev > 0 and len(str(i)) == thr + fiv + sev:
        count += 1

print(count)


### FIXED CODE ###

from itertools import product

N = int(input())
num_list = ["3", "5", "7"]
count = 0

for i in range(3, 10):
    for t in (product(num_list, repeat=i)):
        check = t.count("3")*t.count("5")*t.count("7")
        if int("".join(t)) <= N and check:
            count += 1


print(count)
### BUGGY CODE ###

import numpy as np

def main():
  H, W = map(int, input().split())
  G = [list(input()) for _ in range(H)]
  direction = [[0,1],[0,-1],[1,0],[-1,0]]
  black = np.zeros((H,W))
  que = []
  for i in range(H):
    for j in range(W):
      if G[i][j] == '#':
        que.append([i,j])
        black[i][j] = 0
  while que:
    nh, nw = que.pop(0)
    dh, dw = 0,1
    if 0<=nh+dh<=H-1 and 0<=nw+dw<=W-1 and black[nh+dh][nw+dw] == 0:
      que.append([nh+dh,nw+dw])
      black[nh+dh][nw+dw] = black[nh][nw]+1
    dh, dw = 0,-1
    if 0<=nh+dh<=H-1 and 0<=nw+dw<=W-1 and black[nh+dh][nw+dw] == 0:
      que.append([nh+dh,nw+dw])
      black[nh+dh][nw+dw] = black[nh][nw]+1
    dh, dw = 1,0
    if 0<=nh+dh<=H-1 and 0<=nw+dw<=W-1 and black[nh+dh][nw+dw] == 0:
      que.append([nh+dh,nw+dw])
      black[nh+dh][nw+dw] = black[nh][nw]+1
    dh, dw = -1,0
    if 0<=nh+dh<=H-1 and 0<=nw+dw<=W-1 and black[nh+dh][nw+dw] == 0:
      que.append([nh+dh,nw+dw])
      black[nh+dh][nw+dw] = black[nh][nw]+1
  print(int(np.max(black)))

if __name__ == "__main__":
  main()

### FIXED CODE ###

import copy
from collections import deque
def main():
  H, W = map(int, input().split())
  G = [['#' == x for x in input()] for _ in range(H)]
 
  black = deque([(i, j) for i in range(H) for j in range(W) if G[i][j]])
 
  ans = 0
  while True:
    ans += 1
    next_black = deque()
    while black:
      bi, bj = black.popleft()
      if bi > 0 and not G[bi - 1][bj]:
        G[bi - 1][bj] = True
        next_black.append((bi - 1, bj))
      if bj > 0 and not G[bi][bj - 1]:
        G[bi][bj - 1] = True
        next_black.append((bi, bj - 1))
      if bi < H - 1 and not G[bi + 1][bj]:
        G[bi + 1][bj] = True
        next_black.append((bi + 1, bj))
      if bj < W - 1 and not G[bi][bj + 1]:
        G[bi][bj + 1] = True
        next_black.append((bi, bj + 1))
    if next_black:
       black = copy.copy(next_black)
    else:
       break
  print(ans - 1)
  
if __name__ == "__main__":
  main()
### BUGGY CODE ###

from itertools import accumulate
N, K = map(int, input().split())
A = list(map(int, input().split()))


def calc_imos(arr):
    imos = [0] * (N + 1)
    for i, a in enumerate(arr):
        l = max(0, i - a)
        r = min(N - 1, i + a)
        imos[l] += 1
        imos[r + 1] -= 1
    imos = list(accumulate(imos))
    return imos[:-1]


for k in range(min(50, K)):
    A = calc_imos(A)
print(*A, sep=' ')

### FIXED CODE ###

#%%time
from itertools import accumulate
import numpy as np
from numba import njit

n, k = map(int, input().split())
a = np.array(list(map(int, input().split())), dtype=np.int64)

@njit
def loop1(a):
  #b = [0]*(n+1)
  b = np.zeros(n+1, dtype=np.int64)
  for i in range(n):
    l = max(0, i-a[i])
    r = min(i+a[i]+1, n)
    b[l] += 1
    if r <= n-1: b[r] -= 1
  
  b = np.cumsum(b)[:-1]
  return b
  #a = list(accumulate(b))
  #a = a[:-1]
   
  #if np.all(a == n):
   # break

for q in range(min(42, k)):
  a = loop1(a)
    
print(*a)
### BUGGY CODE ###

def main():
  import sys
  from heapq import heappush, heappop, heapify
  input = sys.stdin.readline
  
  N,D,A = map(int,input().split())
  hq = []
  for i in range(N):
    x,h = map(int,input().split())
    hq.append((x,0,h))
  heapify(hq)

  ans = 0
  b = 0
  while(len(hq) > 0):
    x,a,h = heappop(hq)
    if a == 0:
      if b < h:
        cnt = ((h-b)+A-1)//A
        ans += cnt
        b += A*cnt
        heappush(hq, (x+2*D,1,A*cnt))
    else:
      b -= h
  
  print(ans)

if __name__ == '__main__':
  main()

### FIXED CODE ###

def main():
  import sys
  from heapq import heappush, heappop, heapify
  input = sys.stdin.readline
  
  N,D,A = map(int,input().split())
  hq = []
  for i in range(N):
    x,h = map(int,input().split())
    hq.append((x,0,h))
  heapify(hq)

  ans = 0
  b = 0
  while(len(hq) > 0):
    x,a,h = heappop(hq)
    if a == 0:
      if b < h:
        cnt = ((h-b)+A-1)//A
        ans += cnt
        b += A*cnt
        heappush(hq, (x+2*D,1,A*cnt))
    else:
      b -= h
  
  print(ans)

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

N = int(input())
memo = []
for i in range(N):
    A = int(input())
    if A in memo:
        memo.remove(A)
    else:
        memo.append(A)

print(len(memo))


### FIXED CODE ###

from collections import Counter

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

c = list(Counter(A).items())

ans = 0
for i in c:
    if i[1] % 2:
        ans += 1

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

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

ct = [0]*(sum(A)+1)
ct[0] = 1
ctlen = len(ct)

for a in A:
  for i in range(ctlen-a-1,-1,-1):
    ct[i+a] += ct[i]

ct[0] = 0
medidx = (2**N)//2
n = 0
for i in range(ctlen):
  n += ct[i]
  if n >= medidx:
    print(i)
    exit()

### FIXED CODE ###

import math
N = int(input())
A = list(map(int, input().split()))

sumA = sum(A)
halfA = math.ceil(sumA / 2)
bitset = 1
for a in A:
  bitset |= bitset << a

bitset >>= halfA
i = 0
while i < halfA:
  if bitset & 1:
    print(i+halfA)
    exit()
  bitset >>= 1
  i += 1
print(i+halfA)
### BUGGY CODE ###

import numpy as np 

n = int(input())
a = np.array(list(map(int, input().split())))

for i in range(n):
    _a = np.delete(a, i)
    unique = np.unique(_a)
    for j in range(len(unique)):
        k = np.count_nonzero(_a == unique[j])
        if j == 0:
            if k >= 2:
                total = k * (k - 1) / 2 
            else:
                total = 0
        else:
            if k >= 2:
                total += k * (k - 1) / 2 
    print(int(total))

### FIXED CODE ###

import collections

def solve(N, A):
    c_dict = collections.Counter(A)
    originals = [0 for i in range(N + 1)]
    minus = [0 for i in range(N + 1)]
    
    for (k, v) in c_dict.items():
        originals[k] = v * (v - 1) // 2
        minus[k] = ((v * (v - 1)) - (v - 1) * (v - 2)) // 2
        
    total = sum(originals)
    
    ans = []
    for a in A:
        ans.append(str(total - minus[a]))
    return '\n'.join(ans)
    
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    print(solve(N, A))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
 
n,k = map(int, input().split())
 
################
p = 10**9 + 7
comb_memo = {}
def comb(n,k,p):
  if (n,k) in comb_memo:
    return comb_memo[(n,k)]
  else:
    ans = 1
    for i in range(1,k+1):
      ans = ans * (n - (i-1)) % p
      ans = ans * pow(i, p-2, p)
    comb_memo[(n,k)] = ans
    return ans
################
 
if k >= n:
  ans = comb(2*n-1, n, p) % p
else:
  ans = 0
  for i in range(0,k+1):
    temp = (comb(n-1, i, p) % p) * (comb(n, i, p) % p) % p
    ans = (ans + temp) % p
    
print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-

MOD = 10**9 +7

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret *= kaijo(n)
  ret %= MOD;
  ret *= gyaku_kaijo(r)
  ret %= MOD;
  ret *= gyaku_kaijo(n-r)
  ret %= MOD;
  return ret




 
n,k = map(int, input().split())
 
################
#p = 10**9 + 7
#def comb(n,k,p):
#  ans = 1
#  for i in range(1,k+1):
#    ans = ans * (n - (i-1)) % p
#    ans = ans * pow(i, p-2, p)
#  return ans
################
 
if k >= n:
  ans = nCr(2*n-1, n) % MOD
else:
  ans = 0
  for i in range(0,k+1):
    temp = (nCr(n-1, i) % MOD) * (nCr(n, i) % MOD) % MOD
    ans = (ans + temp) % MOD
    
print(ans)
### BUGGY CODE ###

import numpy as np
import math

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(A)

for i in range(M):
    A[A.argmax()]  =  math.floor(A[A.argmax()] / 2)

print(A.sum())


### FIXED CODE ###

import numpy as np
import math
import heapq

N, M = map(int, input().split())
A = list(map(lambda x: [-int(x),int(x)], input().split()))
heapq.heapify(A)

for i in range(M):
    x = heapq.heappop(A)
    x[1] //= 2
    x[0] = -x[1]
    heapq.heappush(A, x)

ans = 0
for i in range(N):
    ans += A[i][1]
print(ans)
### BUGGY CODE ###

a,b,k=map(int,input().split())

tmp=[i for i in range(a,b+1)]
ans=[]
for a in tmp[:k]:
  ans.append(a)
for a in tmp[-k:]:
  ans.append(a)
out=list(set(ans))
out.sort()
print(*out,sep='\n')

### FIXED CODE ###

a,b,k=map(int,input().split())

ans=[]
for i in range(k):
  if a+i<=b and a+i not in ans:
    ans.append(a+i)
for i in range(k):
  if b-i>=a and b-i not in ans:
    ans.append(b-i)
ans.sort()
print(*ans,sep='\n')
### BUGGY CODE ###

import numpy as np

N, M = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
a.sort()
a.append([np.inf, np.inf])
ans = 0
ind = 0
check = -1
for i in range(1, M+1):
    while a[ind][0] <= i:
        ind += 1
    if a[:ind]:
        m = max(a[:ind], key = lambda x:x[1])
        ans += m[1]
        a.remove(m)
        a.insert(0, [0, 0])
print(ans)

### FIXED CODE ###

import heapq as hq
import numpy as np

N, M = map(int, input().split())
job = [list(map(int, input().split())) for _ in range(N)]
ans = 0
job.sort()
job.append([np.inf, np.inf])
jobhq = []
index = 0
for day in range(1, M + 1):
    while day >= job[index][0]:
        hq.heappush(jobhq, - job[index][1])
        index += 1
    if jobhq:
        ans += - hq.heappop(jobhq)
print(ans)
### BUGGY CODE ###

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

ans = 1
for a in A:
  ans *= a
if 10**18 < ans:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

import sys

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

if 0 in A:
  print(0)
  sys.exit()

ans = 1
for a in A:
  ans *= a
  if 10**18 < ans:
    print(-1)
    sys.exit()
else:
  print(ans)
### BUGGY CODE ###

import sys

class binarySearchTree:
    def __init__(self):
        self.root = None

    def insert(self, key):
        z = Node(key)
        y = None
        x = self.root
        while x:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right

        if y is None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z

    def printBT(self):
        print self.root.inorderTreeWalk()
        print self.root.preorderTreeWalk()

class Node:
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None

    def inorderTreeWalk(self):
        ret = ""
        if self.left:
            ret += self.left.inorderTreeWalk()
        ret += " " + str(self.key)
        if self.right:
            ret += self.right.inorderTreeWalk()

        return ret

    def preorderTreeWalk(self):
        ret = " " + str(self.key)
        if self.left:
            ret += self.left.preorderTreeWalk()
        if self.right:
            ret += self.right.preorderTreeWalk()

        return ret

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    del lines[0]

    bt = binarySearchTree()
    for line in lines:
        if line[0] == "i":
            bt.insert(int(line[6:]))
        else:
            bt.printBT()

### FIXED CODE ###

import sys

class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None

def insert(z):
    global root
    y = None
    x = root
    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y is None:
        root = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z

def inorderTreeWalk(node):
    global In
    if node:
        inorderTreeWalk(node.left)
        In.append(str(node.key))
        inorderTreeWalk(node.right)

def preorderTreeWalk(node):
    global Pre
    if node:
        Pre.append(str(node.key))
        preorderTreeWalk(node.left)
        preorderTreeWalk(node.right)

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    del lines[0]

    root = None
    for line in lines:
        if line[0] == "i":
            insert(Node(int(line.split()[1])))
        else:
            In = []
            Pre = []
            inorderTreeWalk(root)
            print " " + " ".join(map(str, In))
            preorderTreeWalk(root)
            print " " + " ".join(map(str, Pre))
### BUGGY CODE ###

def mi():return map(int,input().split())
def li():return list(mi())

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

for i in range(q):
    qi=list(map(str,input().split()))
    if qi[0]=="1":
        s=s[::-1]
    else:
        if qi[1]=="1":
            s=qi[2]+s
        else:
            s=s+qi[2]
            
print(s)

### FIXED CODE ###

s=input()
q=int(input())
l=""
r=""
flg=True

for i in range(q):
    p=list(map(str,input().split()))
    if p[0]=="1":
        flg=not flg
    else:
        z,f,c=p
        if f=="1":
            if flg:
                l=c+l
            else:
                r=r+c
        else:
            if not flg:
                l=c+l
            else:
                r=r+c
s=l+s+r

if flg:
    ans=s
else:
    ans=s[::-1]
print(ans)
### BUGGY CODE ###

N, M = [int(nm) for nm in input().split()]
AB = []
for n in range(N):
  A, B = [int(ab) for ab in input().split()]
  AB.append([A, B])
money = 0
while M > 0:
  AB_mn = min(AB)
  Ai, Bi = AB_mn[0], AB_mn[1]
  if Bi <= M:
    money += Ai * Bi
    M -= Bi
  else:
    money += Ai * M
    M = 0
  AB.remove(AB_mn)
print(money)

### FIXED CODE ###

N, M = [int(nm) for nm in input().split()]
AB = []
for n in range(N):
  A, B = [int(ab) for ab in input().split()]
  AB.append([A, B])
AB.sort()
money = 0
while M > 0:
  Ai, Bi = AB[0][0], AB[0][1]
  if Bi <= M:
    money += Ai * Bi
    M -= Bi
  else:
    money += Ai * M
    M = 0
  AB.remove(AB[0])
print(money)
### BUGGY CODE ###

n, m = [int(x) for x in input().split(' ')]
l, r = [int(x) for x in input().split(' ')]
res = set(range(l, r+1))

for i in range(int(m-1)):
    l, r = [int(x) for x in input().split(' ')]
    res &= set(range(l, r+1))

print(len(res))


### FIXED CODE ###

n, m = [int(x) for x in input().split(' ')]
lr = [(int(l), int(r)) for l, r in [input().split(' ') for _ in range(m)]]

l = max([x[0] for x in lr])
r = min([x[1] for x in lr])

print(r-l+1 if l <= r else 0)
### BUGGY CODE ###

N = int(input())
S = input()

def f(a, b, c):
    if abs(a-b) == abs(a-c) or abs(a-b) == abs(b-c) or abs(b-c) == abs(a-c):
        return 0
    else:
        return 1

cnt = 0
R, B, G = [], [], []
for i in range(N):
    if S[i] == "R":
        R.append(i)
    elif S[i] == "B":
        B.append(i)
    else:
        G.append(i)

for r in R:
    for b in B:
        for g in G:
            if f(r, b, g):
                cnt += 1
# print(R, G, B)
print(cnt)


### FIXED CODE ###

N = int(input())
S = input()

ans = S.count("R")*S.count("B")*S.count("G")
for i in range(N):
    for d in range(N):
        j = i+d
        k = j+d
        if k < N:
            if S[i] != S[j] and S[k] != S[j] and S[k] != S[i]:
                ans -= 1
print(ans)
### BUGGY CODE ###

"""
D - Lazy Faith
"""


def solve():
    # データ読込
    A, B, Q = map(int, input().split())
    shrines = [int(input()) for i in range(A)]
    temple = [int(input()) for i in range(B)]
    question = [int(input()) for i in range(Q)]
    # 問題計算
    for q in question:
        t_list = []
        # 寺から神社に行くときの計算
        t_s = 0
        abs_temple = [abs(q - t) for t in temple]
        target = abs_temple.index(min(abs_temple))
        t_temple = temple[target]
        t_s += abs(q - t_temple)
        abs_shrines = [abs(t_temple - s) for s in shrines]
        t_s += min(abs_shrines)
        t_list.append(t_s)
        if abs_temple.count(min(abs_temple)) > 1:
            # 同じ距離の寺が二つあるときの考慮
            t_s2 = 0
            t_temple = temple[target + 1]
            t_s2 += abs(q - t_temple)
            abs_shrines = [abs(t_temple - s) for s in shrines]
            t_s2 += min(abs_shrines)
            t_list.append(t_s2)
        # 神社から寺に行くときの計算
        s_t = 0
        abs_shrines = [abs(q - s) for s in shrines]
        target = abs_shrines.index(min(abs_shrines))
        t_shrines = shrines[target]
        s_t += abs(q - t_shrines)
        abs_temple = [abs(t_shrines - t) for t in temple]
        s_t += min(abs_temple)
        t_list.append(s_t)
        if abs_shrines.count(min(abs_shrines)) > 1:
            # 同じ距離の寺が二つあるときの考慮
            s_t2 = 0
            t_shrines = shrines[target + 1]
            s_t2 += abs(q - t_shrines)
            abs_temple = [abs(t_shrines - t) for t in temple]
            s_t2 += min(abs_temple)
            t_list.append(s_t2)
        # 出力
        print(min(t_list))


if __name__ == '__main__':
    solve()


### FIXED CODE ###

"""
D - Lazy Faith
"""
# 解説を参考に作成（bisect）
import bisect


def solve():
    # データ読込
    A, B, Q = map(int, input().split())
    si = [-float('inf')] + [int(input()) for i in range(A)] + [float('inf')]
    ti = [-float('inf')] + [int(input()) for i in range(B)] + [float('inf')]
    xi = [int(input()) for i in range(Q)]
    # 問題計算
    for x in xi:
        txi = bisect.bisect_left(ti, x)
        left_t = ti[txi - 1]
        right_t = ti[txi]
        sxi = bisect.bisect_left(si, x)
        left_s = si[sxi - 1]
        right_s = si[sxi]
        print(min(abs(x - min(left_t, left_s)),
                  abs(x - max(right_t, right_s)),
                  abs(x - right_t) + abs(right_t - left_s),
                  abs(x - left_t) + abs(left_t - right_s),
                  abs(x - right_s) + abs(right_s - left_t),
                  abs(x - left_s) + abs(left_s - right_t)))


if __name__ == '__main__':
    solve()