Harryxun/stf_run huggingface dataset:
from collections import deque, Counter, defaultdict
from functools import lru_cache
from itertools import permutations
from heapq import (
    heappush,
    heappop,
    heapreplace,
    heappushpop,
    heapify,
    merge,
    nlargest,
    nsmallest,
)
from statistics import mean, median, mode


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    return a * b // gcd(a, b)


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

clcm = 1
for num in a:
    clcm = lcm(clcm, num)

tot = 0
for num in a:
    tot = (tot + clcm // num) % 1000000007

print(tot)


### FIXED CODE ###

def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)

def lcm(a,b):
  return a * b // gcd(a,b)

n = int(input())
av = list(map(int, input().split(' ')))
alcm = 1
for i in av:
  alcm = lcm(alcm, i)

tot = 0
for i in range(n):
  tot += alcm // av[i]

print(tot % 1000000007)
def main():
    H, W = list(map(int, input().split(" ")))
    a = []
    for r in range(H):
        a += [input()]
    output = solve(H, W, a)
    for s in output:
        print(s)
    return

#________________________________________
#  Solve
#________________________________________
def solve(H, W, a):
    """
    解答のコード
    """
    index_list = []
    for _r in range(H):
        for _c in range(W):
            if a[_r][_c] is not ".":
                break
            if _c == W-1:
                index_list += [_r]
    for i in index_list:
        del a[i]

    for _c in range(len(a[0])):
        for _r in range(len(a)):
            if a[_r][_c] is not ".":
                break
            if _r == len(a)-1:
                index_list += [_c]
    a = list(map(list, zip(*a)))
    for i in index_list:
        del a[i]
    a = list(map(list, zip(*a)))
    a = [ "".join(a[i]) for i in range(len(a))]
    return a
#________________________________________


if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    H, W = list(map(int, input().split(" ")))
    a = []
    for r in range(H):
        a += [input()]
    output = solve(H, W, a)
    for s in output:
        print(s)
    return

#________________________________________
#  Solve
#________________________________________
def solve(H, W, a):
    """
    解答のコード
    """
    index_list = []
    for _r in range(H):
        for _c in range(W):
            if a[_r][_c] is not ".":
                break
            if _c == W-1:
                index_list += [_r]
    j = 0
    for i in index_list:
        del a[i-j]
        j += 1

    index_list = []
    a = list(map(list, zip(*a)))
    for _r in range(len(a)):
        for _c in range(len(a[0])):
            if a[_r][_c] is not ".":
                break
            if _c == len(a[0])-1:
                index_list += [_r]
    j = 0
    for i in index_list:
        del a[i-j]
        j += 1
    a = list(map(list, zip(*a)))
    a = [ "".join(a[i]) for i in range(len(a))]
    return a
#________________________________________


if __name__ == "__main__":
    main()
n = int(input())
slist = []
for i in range(n):
    s = sorted(list(input()))
    slist.append(s)

common = [s for s in slist[0]]

for i in range(1,n):
    poplist = []
    for j in range(len(common)):
        if common[j] in slist[i]:
            slist[i].remove(common[j])
        else:
            poplist.append(j)
    for j in range(len(poplist)):
        common.pop(poplist[j])
    #print(common)
common.sort()
print(''.join(common))

### FIXED CODE ###

n = int(input())
slist = [input()for i in range(n)]

alp = {chr(i):float('inf') for i in range(97,97+26)}

for i in range(len(slist)):
    sdic = {chr(i):0 for i in range(97,97+26)}
    for j in range(len(slist[i])):
        sdic[slist[i][j]] += 1
    
    for k in alp:
        alp[k] = min(alp[k],sdic[k])

alplist = sorted(list(alp.items()))
ans = ''
for i in range(26):
    ans += alplist[i][0]*alplist[i][1]
print(ans)
#一個だけRE、わからねえ
#解答見る
import sys
#sys.setrecursionlimit(1005)
h,w=map(int,input().split())

def go_next(I,J,n):
    n+=1
    global dp,w,h
    if n>1000:
        return
    if 0<=I<h-1:
        if x[I+1][J]=="." and dp[I+1][J]>dp[I][J]+1:
            dp[I+1][J]=dp[I][J]+1
            go_next(I+1,J,n)
    if 0<I<=h-1:
        if x[I-1][J]=="." and dp[I-1][J]>dp[I][J]+1:
            dp[I-1][J]=dp[I][J]+1
            go_next(I-1,J,n)
    if 0<=J<w-1:
        if x[I][J+1]=="." and dp[I][J+1]>dp[I][J]+1:
            dp[I][J+1]=dp[I][J]+1
            go_next(I,J+1,n)
    if 0<J<=w-1:
        if x[I][J-1]=="." and dp[I][J-1]>dp[I][J]+1:
            dp[I][J-1]=dp[I][J]+1
            go_next(I,J-1,n)

x=[]
for i in range(h):
    x.append(list(input()))
#print(x)
c=0
for i in range(h):
    for j in range(w):
        if x[i][j]==".":
            c+=1
dp=[[10000000000 for i in range(w)]for j in range(h)]
dp[0][0]=1
go_next(0,0,0)
if dp[h-1][w-1]==10000000000:
    print(-1)
else:
    print(c-dp[h-1][w-1])


### FIXED CODE ###

#一個だけRE、わからねえ
#解答見る
import sys
sys.setrecursionlimit(1005)
h,w=map(int,input().split())

def go_next(I,J,n):
    n+=1
    global dp,w,h
    if n>1000:
        return
    if 0<=I<h-1:
        if x[I+1][J]=="." and dp[I+1][J]>dp[I][J]+1:
            dp[I+1][J]=dp[I][J]+1
            go_next(I+1,J,n)
    if 0<I<=h-1:
        if x[I-1][J]=="." and dp[I-1][J]>dp[I][J]+1:
            dp[I-1][J]=dp[I][J]+1
            go_next(I-1,J,n)
    if 0<=J<w-1:
        if x[I][J+1]=="." and dp[I][J+1]>dp[I][J]+1:
            dp[I][J+1]=dp[I][J]+1
            go_next(I,J+1,n)
    if 0<J<=w-1:
        if x[I][J-1]=="." and dp[I][J-1]>dp[I][J]+1:
            dp[I][J-1]=dp[I][J]+1
            go_next(I,J-1,n)

x=[]
for i in range(h):
    x.append(list(input()))
#print(x)
c=0
for i in range(h):
    for j in range(w):
        if x[i][j]==".":
            c+=1
dp=[[10000000000 for i in range(w)]for j in range(h)]
dp[0][0]=1
go_next(0,0,0)
if dp[h-1][w-1]==10000000000:
    print(-1)
else:
    print(c-dp[h-1][w-1])
S=str(input())
ListNum=[]
ListNUM=[]
for i in range(0,len(S),1):
  if i<(len(S)-2):
    Num=100*int(S[i])+10*int(S[i+1])+int(S[i+2])
    ListNum.append(Num)

for j in range(0,len(ListNum),1):
  NUm=int(ListNum[i])-753
  NUM=int(NUm**2)
  ListNUM.append(NUM)

mini=min(ListNUM)
ans=ListNUM.index(mini)
print(ListNum[ans])


### FIXED CODE ###

S=str(input())
ListNum=[]
ListNUm=[]
ListNUM=[]
for i in range(0,len(S),1):
  if i<len(S)-2:
    Num=100*int(S[i])+10*int(S[i+1])+int(S[i+2])
    NUm=Num-753
    NUM=NUm**2
    ListNum.append(Num)
    ListNUm.append(NUm)
    ListNUM.append(NUM)
posi=ListNUM.index(min(ListNUM))

if ListNUm[posi]<0:
  ListNUm[posi]=ListNUm[posi]*(-1)
print(ListNUm[posi])
import numpy as np

mod = 10**9 + 7
N = input()
A = np.atleast_2d(list(map(int, input().split()))) % mod

print((np.sum((A ^ A.T) % mod) % mod) // 2)

### FIXED CODE ###

import numpy as np
 
mod = 10**9 + 7
max_digit = 60
N = int(input())
A = np.array(list(map(int, input().split())))

result = 0
base = 1
for _ in range(max_digit + 1):
  a = A % 2
  c = np.count_nonzero(a == 0)
  result = (result + (base*(N - c)*c) % mod) % mod
  A = A >> 1
  base *= 2

print(result)
K,X=map(int,input().split())
If K*500>=X:
    print(‘Yes’)
else:
    print(‘No’) 

### FIXED CODE ###

K,X=map(int,input().split())
if K*500>=X:
    print('Yes')
else:
    print('No')
n = int(input())
s = list(list(input().split()) for _ in range(n))
ans = [s.index(i)+1 for i in sorted(s, key=lambda x:(x[0], -int(x[1])))]
print(i) for i in ans


### FIXED CODE ###

n = int(input())
s = list(list(input().split()) for _ in range(n))
ans = [s.index(i)+1 for i in sorted(s, key=lambda x:(x[0], -int(x[1])))]
for i in ans: print(i)
x = int(input())

if x = 0:
  print(1)
elif x = 1:
  print(0)

### FIXED CODE ###

x = int(input())
 
if x == 0:
  print(1)
elif x == 1:
  print(0)
s = int(input())
an = []
an.append(s)
n = s
while an.count(4) != 2:
    if n % 2 == 0:
        n /= 2
        an.append(int(n))
    else:
        n = 3 * n + 1
        an.append(int(n))
print(an.index(4) + 4)



### FIXED CODE ###

x, y, z = map(int, input().split())
print(int(x * y / 2))
S=input()
N=len(S)
Slis=[]
for i in range(N):
  Slis+=[int(S[i])]
T=[int(S[i:]) for i in range(N)]
MOD=[0 for i i range(2019)]
for i in range(N):
  tmp=T[i]%2019
  MOD[tmp]+=1
ans=0
for i in range(2019):
  tmp=T[i]
  ans+=tmp*(tmp-1)//2
print(ans)

### FIXED CODE ###

S=input()
N=len(S)
Slis=[]
for i in range(N):
  Slis+=[int(S[i])]
T=[0 for i in range(N+1)]#T[i]はi桁より右側の数字


ten=1

for i in range(N):
  T[N-i-1]=(T[N-i]+ten*Slis[N-i-1])%2019
  ten=(ten*10)%2019

MOD=[0 for i in range(2019)]
for i in range(N+1):
  tmp=T[i]%2019
  MOD[tmp]+=1


  
ans=0

for i in range(2019):
  tmp=MOD[i]
  ans+=tmp*(tmp-1)//2
print(ans)
D, G = map(int, input().split())
PC = [tuple(map(int, input().split()))]

res = float("inf")
for bit in range(1 << D):
    sum = 0
    num = 0
    for i in range(D):
        if ((bit >> i) & 1):
            sum += (i + 1) * 100 * P[i] + C[i]
            num += P[i]
    if sum >= G:
        res = min(res, num)
    for i in range(D - 1, -1, -1):
        if ((bit >> i) & 1):
            continue
        for j in range(P[i] - 1):
            sum += (i + 1) * 100
            num + +
        if sum >= G:
            res = min(res, num)
            break
    print(res)


### FIXED CODE ###

D, G = map(int, input().split())
PC = [tuple(map(int, input().split())) for _ in range(D)]

res = float("inf")
for bit in range(1 << D):
    summ = 0
    num = 0
    for i in range(D):
        if ((bit >> i) & 1):
            summ += (i + 1) * 100 * PC[i][0] + PC[i][1]
            num += PC[i][0]
    if summ >= G:
        res = min(res, num)
    for i in range(D - 1, -1, -1):
        if ((bit >> i) & 1):
            continue
        for _ in range(PC[i][0] - 1):
            summ += (i + 1) * 100
            num += 1
            if summ >= G:
                res = min(res, num)
                break
print(res)
N,K = map(int,input().split())
h = list(map(int,input().split()))

dp = [float('inf') for i in range(N-1)]

for i in range(N-1):
  for j in range(1,K+1):
    if i+j>N: continue
    dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]))
    
print(dp[-1])

### FIXED CODE ###

import numpy as np

N,K = map(int, input().split())
h = np.array(list(map(int,input().split())))

dp = np.zeros(N, dtype = int)

for i in range(1,N):
  s = max(i-K,0)
  dp[i] = np.min(dp[s:i]+ np.abs(h[s:i] - h[i]))
  
print(dp[-1])
from itertools import product

def mat2_mul(X, Y):
	z = [[0, 0], [0, 0]]
	for (i, j, k) in product(range(2), range(2), range(2)):
		z[i][j] += X[i][k] * Y[k][j]
	return z

def mat2_pow(X, n):
	if n == 0:
		return [[1, 0], [0, 1]]
	elif n % 2:
		return mat2_mul(X, mat2_pow(X, n - 1))
	else:
		half_pow = mat2_pow(X, n / 2)
		return mat2_mul(half_pow, half_pow)

def fib(n):
	if n == 0:
		return 0
	else:
		f = [[0, 1], [1, 1]]
	return mat2_pow(f, n - 1)[1][1]

def main():
    n, m = map(int,input().split())
    mlis = []
    for _ in range(m):
        a = int(input())
        mlis.append(a)
    ans = 1
    mae = 0

   infi = 10 **9 + 7
   for num in mlis:
       ans *= fibona(num-mae)
       ans %= infi
       mae = num + 1

    nobori = n - mae + 1
    ans *= fibona(nobori) 
    ans %= infi
    print(int(ans))
    



if __name__ == "__main__":
    main()

### FIXED CODE ###

from itertools import product

def mat2_mul(X, Y):
	z = [[0, 0], [0, 0]]
	for (i, j, k) in product(range(2), range(2), range(2)):
		z[i][j] += X[i][k] * Y[k][j]
	return z

def mat2_pow(X, n):
	if n == 0:
		return [[1, 0], [0, 1]]
	elif n % 2:
		return mat2_mul(X, mat2_pow(X, n - 1))
	else:
		half_pow = mat2_pow(X, n / 2)
		return mat2_mul(half_pow, half_pow)

def fibona(n):
	if n == 0:
		return 0
	else:
		f = [[0, 1], [1, 1]]
	return mat2_pow(f, n - 1)[1][1]

def main():
    n, m = map(int,input().split())
    mlis = []
    for _ in range(m):
        a = int(input())
        mlis.append(a)
    ans = 1
    mae = 0

    infi = 10 ** 9 + 7
    for num in mlis:
        ans *= fibona(num-mae)
        ans %= infi
        mae = num + 1

    nobori = n - mae + 1
    ans *= fibona(nobori) 
    ans %= infi
    print(int(ans))
    



if __name__ == "__main__":
    main()
n = int(input())
aka = []
ao = []
for _ in range(n):
    ab = sorted(list(map(int, input().split())), key=lambda x:x[1], reverse=True)
    aka.append(ab)
for _ in range(n):
    cd = sorted(list(map(int, input().split())))
    ao.append(cd)
count = 0
for a, b in aka:
    for c, d in ao:
        if a<c and b<d:
            ao.remove(c,d)
            count+=1
            break
print(count)

### FIXED CODE ###

n = int(input())
aka = []
ao = []
for _ in range(n):
    ab = list(map(int, input().split()))
    aka.append(ab)
aka = sorted(aka, key=lambda x:x[1], reverse=True)
for _ in range(n):
    cd = list(map(int, input().split()))
    ao.append(cd)
ao = sorted(ao)
count = 0
for a, b in aka:
    for c, d in ao:
        if a<c and b<d:
            ao.remove([c,d])
            count+=1
            break
print(count)
if N % 3:
	print("Yes")
else:
  	print("No")

### FIXED CODE ###

s = input()
if "7" in s:
    print("Yes")
else:
    print("No")
w=input()
s=[0]*123
for i in len(w):
    s[ord(w[i-1])]+=1
c=1
for i in range(97,97+26):
    if s[i]%2==1:
        c=0
        break
if c==1:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

w=input()
s=[0]*123
for i in range(len(w)):
    s[ord(w[i-1])]+=1
c=1
for i in range(97,97+26):
    if s[i]%2==1:
        c=0
        break
if c==1:
    print("Yes")
else:
    print("No")
n=int(input())
l=[]
p=0
for I in range(1,n+1):
 l.append(int(input())
l.sort()
for I in l:
 p+=I
print(p+max(l))

### FIXED CODE ###

n=int(input())
l=[]
s=0
for i in range(1,n+1):
 l.append(int(input()))
l.sort()
for i in l:
 s+=i
print(int(s-0.5*max(l)))
a,b,c,d = map(int, input().split())

if abs(c-a) <= d:
	print(“Yes”)
elif abs(b-a) + abs(c-b) <= 2*d:
	print(“Yes”)
else:
	print(“No”)

### FIXED CODE ###

a,b,c,d = map(int, input().split())

if abs(c-a) <= d:
	print('Yes')
elif abs(b-a) <= d and abs(c-b) <= d:
	print('Yes')
else:
	print('No')
n = int(input())

if n % 2 == 0:

    print(1 / 2)

else:

    print((n + 1) / 2n)

### FIXED CODE ###

n = int(input())

if n % 2 == 0:

    print(1 / 2)

else:

    print((n + 1) / 2 / n)
import re
S = input()
c = r"A[a-z]+C[a-z]+$"
print("AC" if re.match(c,s) else "WA")



### FIXED CODE ###

import re
S = input()
c = r"A[a-z]+C[a-z]+$"
print("AC" if re.match(c,S) else "WA")
num = input()
seq = input()
num_R = seq.count(R)
if num_R > num // 2:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

num = int(input())
seq = input()
num_R = seq.count('R')
if num_R > num // 2:
  print('Yes')
else:
  print('No')
import sys
sys.setrecursionlimit(1000000)
N = int(input())
edges = [[] for _ in range(N)]
cnt_edges = [0]*N
colors = [0]*((N+2)*(10**5))
A = []
K = 0
for i in range(N-1):
    a,b = [int(x) for x in input().split()]
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

    cnt_edges[a-1]+=1
    cnt_edges[b-1]+=1
    A.append((a-1,b-1))
#%%
K = max(cnt_edges)

stk = [(0,0)]
seen = set()
while(stk):
    n,used_color = stk.pop()
    available_color = [i for i in range(1,K+1)]
    if(used_color!=0):
        available_color.remove(used_color)
    next_stk = []
    for next in edges[n]:
        if(next in seen):
            continue
        col = available_color.pop()
        next_stk.append((next,col))

        colors[next*(10**5)+n] = col
        colors[n*(10**5)+next] = col
    stk = next_stk + stk
    seen.add(n)

print(K)
for edge in A:
    a,b = edge
    col = colors[a*(10**5)+b]
    print(col)


### FIXED CODE ###

N = int(input())
edges = [[] for _ in range(N)]
cnt_edges = [0]*N
colors = [0]*(N-1)
di = {}
A = []
K = 0
for i in range(N-1):
    a,b = [int(x) for x in input().split()]
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

    K=max(K,len(edges[a-1]),len(edges[b-1]))
    di[(a-1,b-1)] = i
    di[(b-1,a-1)] = i
    A.append((a-1,b-1))
#%%
#K = max(cnt_edges)

stk = [(0,0)]
seen = set()
while(stk):
    n,used_color = stk.pop()
    available_color = 1
    next_stk = []
    for next in edges[n]:
        if(next in seen):
            continue
        if(available_color == used_color):
            available_color += 1
        next_stk.append((next,available_color))
        i = di[(next,n)]
        colors[i] = available_color
        available_color += 1
    stk += next_stk
    seen.add(n)

print(K)
for col in colors:
    print(col)
a,b,c=map(int,raw_input().split())
if a<=b and b<=c:
  print a + ' ' + b + ' ' + c
elif a<=c and c<=b:
  print a + ' ' + c + ' ' + b
elif b<=a and a<=c:
  print b + ' ' + a + ' ' + c
elif b<=c and c<=a:
  print b + ' ' + c + ' ' + a
elif c<=b and b<=a:
  print c + ' ' + b + ' ' + a
elif c<=a and a<=b:
  print c + ' ' + a + ' ' + b

### FIXED CODE ###

a = map(int, raw_input().split())
a.sort()
for i in range(len(a)):
    print a[i],
num=int(input())
list_num=list(input)
for i in range(list_num):
  if i=7:
    return Yes
    
return No
  
    
  


### FIXED CODE ###


N=input()
if N.count('7')==0:
  print('No')
  
else:
  print('Yes')
import sys, itertools
input = sys.stdin.readline

n = int(input())
ll = []
for i in range(n):
  a = int(input())
  for j in range(a):
    x, y = map(int, input().split())
  ll.append([i, x-1, y])

ans = 0

for p in itertools.product([1,0], repeat=n):
  ok = 1
  for l in ll:
    if p[l[0]] == 1 and p[l[1]] != l[2]:
      ok = 0
      break
  if ok:
    ans = max(ans, sum(p))

print(ans)

### FIXED CODE ###

n = int(input())
la, lxy = [], []
for i in range(n):
  a = int(input())
  la.append(a)
  xy = []
  for j in range(a):
    xy.append(list(map(int, input().split())))
  lxy.append(xy)

lb = []
for i in range(2**n):
  lb += [str(bin(i))[2:].zfill(n)]
lc = [sum(int(j) for j in i) for i in lb]
lc, lb = zip(*sorted(zip(lc, lb), reverse=True))
lb = [[int(j) for j in i] for i in lb]

for l in lb:
  ok = 1
  for i in range(n):
    a = la[i]
    for j in range(a):
      x, y = lxy[i][j]
      if l[i] == 1 and l[x-1] != y:
        ok = 0
        break
  if ok:
    print(sum(int(k) for k in l))
    break
else:
  print(0)
N, Q = map(int,input().split())
edge = [[] for i in range(N+1)]

for _ in range(N-1):
    a, b = map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)

node = [[[],0] for i in range(N+1)] #[childrens],counter
    
def dfs(parent,i):
    for k in edge[i]:
        if parent != k:
            node[i][0].append(k)
            dfs(i,k)

def dfs_solve(p,x):
    node[p][1] += x
    for i in node[p][0]:
        dfs_solve(i,x)
        
dfs(-1,1)

for _ in range(Q):
    p, x = map(int,input().split())
    dfs_solve(p,x)

for i in range(1,N+1):
    print(node[i][1])

### FIXED CODE ###

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

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
 
graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
 
value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(parent,i,add):
    for k in graph[i]:
        if k != parent:
            value[k] += add
            dfs(i,k,value[k])
    

dfs(0,1,value[1])

ans = value[1:]

print(*ans)
import sys

""" print('sys.argv         : ', sys.argv)
print('type(sys.argv)   : ', type(sys.argv))
print('len(sys.argv)    : ', len(sys.argv))

print('sys.argv[0]      : ', sys.argv[0])
print('sys.argv[1]      : ', sys.argv[1])
print('type(sys.argv)   : ', type(sys.argv[1]))
 """
s = sys.argv[1]
# print(len(s))

if len(s) == 4:
    if s.count(s[0]) == 2:
        if s.count(s[1]) == 2:
            if s.count(s[2]) == 2:
                if s.count(s[3]) == 2:
                    print("Yes")
                    exit()
print("No")
exit()


### FIXED CODE ###

import sys


#s = sys.argv[1]
s = input()
if len(s) == 4:
    if s.count(s[0]) == 2:
        if s.count(s[1]) == 2:
            if s.count(s[2]) == 2:
                if s.count(s[3]) == 2:
                    print("Yes")
                    exit()
print("No")
exit()
import bisect

A, B, Q = [int(e) for e in input().split()]
ss = [int(input()) for _ in range(A)]
tt = [int(input()) for _ in range(B)]
xx = [int(input()) for _ in range(Q)]

for x in xx:
    buf = []
    # s right, t
    idx_s_right = min(bisect.bisect_left(ss, x), A-1)
    s_right = ss[idx_s_right]

    idx_st_right = min(bisect.bisect_left(tt, s_right), B-1)
    idx_st_left = max(0, idx_st_right - 1)
    t_right = tt[idx_st_right]
    t_left = tt[idx_st_left]

    buf.append(abs(s_right - x) + abs(t_right - s_right))
    buf.append(abs(s_right - x) + abs(t_left - s_right))
    s_right = None 
    t_right = None
    s_left = None
    t_left = None

    # s left, t
    idx_s_left = max(0, idx_s_right - 1)
    if idx_s_left != idx_s_right:
        s_left = ss[idx_s_left]

        idx_st_right = min(bisect.bisect_left(tt, s_left), B-1)
        idx_st_left = max(0, idx_st_right - 1)
        t_right = tt[idx_st_right]
        t_left = tt[idx_st_left]

        buf.append(abs(s_left - x) + abs(t_right - s_left))
        buf.append(abs(s_left - x) + abs(t_left - s_left))
    
        s_right = None 
        t_right = None
        s_left = None
        t_left = None

    # t right, r 
    idx_t_right = min(bisect.bisect_left(tt, x), B-1)
    t_right = tt[idx_t_right]

    idx_ts_right = min(bisect.bisect_left(ss, t_right), A-1)
    idx_ts_left = max(0, idx_ts_right - 1)
    s_right = ss[idx_ts_right]
    s_left = ss[idx_ts_left]

    buf.append(abs(t_right - x) + abs(s_right - t_right))
    buf.append(abs(t_right - x) + abs(s_left - t_right))
    
    s_right = None 
    t_right = None
    s_left = None
    t_left = None

    # s left, t
    idx_t_left = max(0, idx_t_right - 1)
    if idx_t_left != idx_t_right:
        t_left = ss[idx_t_left]

        idx_ts_right = min(bisect.bisect_left(ss, t_left), A-1)
        idx_ts_left = max(0, idx_ts_right - 1)
        s_right = tt[idx_ts_right]
        s_left = tt[idx_ts_left]

        buf.append(abs(t_left - x) + abs(s_right - t_left))
        buf.append(abs(t_left - x) + abs(s_left - t_left))

    print(min(buf))


### FIXED CODE ###

import bisect

A, B, Q = [int(e) for e in input().split()]
ss = [int(input()) for _ in range(A)]
tt = [int(input()) for _ in range(B)]
xx = [int(input()) for _ in range(Q)]
INF = 10 ** 18
for x in xx:
    idx_s_right = min(bisect.bisect_left(ss, x), A-1)
    idx_s_left = max(0, idx_s_right - 1)
    stmps = [ss[idx_s_right], ss[idx_s_left]]

    ttmps = [] 
    idx_t_right = min(bisect.bisect_left(tt, x), B-1)
    idx_t_left = max(0, idx_t_right - 1)
    ttmps = [tt[idx_t_right], tt[idx_t_left]]

    mem = INF
    for s in stmps:
        for t in ttmps:
            d_s = abs(s - x) + abs(t - s)
            d_t = abs(t - x) + abs(s - t)
            mem = min(mem, d_s, d_t)
    print(mem)