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

N = int(input())
A = list(map(int,input().split()))
MOD = 10**9+7

MAXN = 10**6+10
facts = [-1,-1] + [0]*MAXN
p = 2
while p*p <= MAXN:
    if facts[p] == 0:
        for q in range(p*p,MAXN+1,p):
            if facts[q]==0:
                facts[q] = p
    p += 1

from collections import Counter
ctr = Counter()
for a in A:
    c = Counter()
    while facts[a] > 0:
        c[facts[a]] += 1
        a //= facts[a]
    c[a] += 1
    ctr |= c

ans = 0
for a in A:
    c = Counter()
    while facts[a] > 0:
        c[facts[a]] += 1
        a //= facts[a]
    c[a] += 1
    t = 1
    for k,v in (ctr - c).items():
        t *= k**v
    ans += t
ans %= MOD
print(ans)

### FIXED CODE ###

from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9+7

lcm = 1
for a in A:
    lcm = lcm // gcd(lcm,a) * a

ans = 0
for a in A:
    ans += lcm // a
ans %= MOD
print(ans)
### BUGGY CODE ###

h, w = map(int, input().split())
g = [[True]*(w+2)]
bp = []
for i in range(h):
    A = input()
    b = [False]*w
    for j, a in enumerate(A):
        if a == '#':
            bp.append([i+1, j+1])
            b[j] = True
    g.append([True] + b + [True])
g.append([True]*(w+2))

cnt = 0
while bp:
    p = []
    for i, j in bp:
        if not g[i+1][j]:
            g[i+1][j] = True
            p.append([i+1, j])
        if not g[i-1][j]:
            g[i-1][j] = True
            p.append([i-1, j])       
        if not g[i][j+1]:
            g[i][j+1] = True
            p.append([i, j+1])
        if not g[i][j-1]:
            g[i][j-1] = True
            p.append([i, j-1])
    cnt += 1
    bp = p
print(cnt-1)

### FIXED CODE ###

h, w = map(int, input().split())
g = [[True]*(w+2)]
for i in range(h):
    g.append([True] + [a == '#' for a in input()] + [True])
g.append([True]*(w+2))

bp = []
for i in range(1, h+1):
    for j in range(1, w+1):
        if g[i][j]:
            bp.append((i, j))

cnt = 0
while bp:
    p = []
    for i, j in bp:
        if not g[i+1][j]:
            g[i+1][j] = True
            p.append((i+1, j))
        if not g[i-1][j]:
            g[i-1][j] = True
            p.append((i-1, j))       
        if not g[i][j+1]:
            g[i][j+1] = True
            p.append((i, j+1))
        if not g[i][j-1]:
            g[i][j-1] = True
            p.append((i, j-1))
    cnt += 1
    bp = p
print(cnt-1)
### BUGGY CODE ###

N, M = map(int, input().split())

a = []
for _ in range(M):
    a.append(int(input()))

val = [0,1]
for i in range(1,N+1):
    ans = val[0] + val[1]
    val[0] = val[1]
    val[1] = ans
    if i in a:
        val[1] = 0

print(ans%(10**9+7))

### FIXED CODE ###

N, M = map(int, input().split())

a = []
for _ in range(M):
    a.append(int(input()))

val = [0,1]
for i in range(1, N + 1):
    ans = val[-2] + val[-1]
    val.append(ans)
    if len(a) > 0:
        if i == a[0]:
            val[-1] = 0
            a.pop(0)

print(ans % (10**9 +7))
### BUGGY CODE ###

import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n=int(input())
a=tuple(map(int,input().split() ))

ans={(i,i+1)for i in range(1,n+1)}
def f(l,r):
    if l<r-1:
        if (l,r-1)not in ans:ans.add((l,r-1));f(l,r-1)
        if (l+1,r)not in ans:ans.add((l+1,r));f(l+1,r)

from itertools import accumulate
b=[0]+list(accumulate(a))
xor=[0]
ar=0
for r_minus1,i in enumerate(a):
    ar^=i
    #(ng,ok]type
    ok,ng=r_minus1,-1
    br=b[r_minus1+1]
    xor.append(ar)

    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if ar^xor[mid]==br-b[mid]:ok=mid
        else:ng=mid
    ans.add((ok,r_minus1+1))
    f(ok,r_minus1+1)
print(len(ans)-1)

### FIXED CODE ###

import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n=int(input())
a=tuple(map(int,input().split() ))
from itertools import accumulate
b=[0]+list(accumulate(a))
xor=[0]
ar=0
for i in a:ar^=i;xor.append(ar)
right=0
ub=-1
ans=0
for left in range(n):
    while right<n and xor[right+1]^xor[left]==b[right+1]-b[left]:
        right+=1
    #出来上がるのは半開区間[left,right)
    if xor[right]^xor[left]==b[right]-b[left]:
        ans+=(right-left)*(right-left-1)//2
        if ub>left:
            ans-=(ub-left)*(ub-left-1)//2
        ub=right
    if right==left:right+=1
    
print(ans+n)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split(' ')))
for i in range(N-1):
    k=0
    for j in range(N-1):
        if A[j]==i+1:
            k=k+1
        if A[j]>i+1:
            break
    print(k)
print(0)

### FIXED CODE ###

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

ans = [0] * n
for i in a:
    ans[i] += 1

for i in range(n-1):
    print(ans[i+1])
print(0)
### BUGGY CODE ###

N, M = map(int, input().split())
ans = []

for i in range(M):
    tmp = list(map(int, input().split()))
    if i == 0:
        ans = [x for x in range(tmp[0], tmp[1]+1)]
    else:
        cur = [x for x in range(tmp[0], tmp[1]+1)]
        ans = [x for x in cur if x in ans]

print(len(ans))

### FIXED CODE ###

N, M = map(int, input().split())
L = 0
R = 10**5

for i in range(M):
    tmp = list(map(int, input().split()))
    if L<tmp[0]:
        L = tmp[0]
    if R>tmp[1]:
        R = tmp[1]

ans = [x for x in range(L, R+1)]

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

import sys
import io
#sys.stdin = io.StringIO(input_string)
sys.setrecursionlimit(10 ** 6)
def _input():
    return sys.stdin.readline()[:-1]
    
def resolve():
	from collections import deque
	
	n, q = map(int, input().split())
	adj = [[] for i in range(n+1)]
	for i in range(n-1):
		a, b = map(int, input().split())
		adj[a-1].append(b-1)
		adj[b-1].append(a-1)
	ans = [0 for i in range(n)]
	for i in range(q):
		p, x = map(int, input().split())
		p -= 1
		ans[p] += x
#	print(f"{adj=}\n{ans=}")

	def dfs(now, prv):
		for next in adj[now]:
#			print(f"{now=}, {next=}")
			if next == prv:
				continue
			ans[next] += ans[now]
			dfs(next, now)

	dfs(0, 0)
	print(*ans)

resolve()


### FIXED CODE ###

import sys
import io
#sys.stdin = io.StringIO(input_string)
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]
    
def resolve():
	from collections import deque
	
	n, q = map(int, input().split())
	adj = [[] for i in range(n+1)]
	for i in range(n-1):
		a, b = map(int, input().split())
		adj[a-1].append(b-1)
		adj[b-1].append(a-1)
	ans = [0 for i in range(n)]
	for i in range(q):
		p, x = map(int, input().split())
		p -= 1
		ans[p] += x
#	print(f"{adj=}\n{ans=}")

	def dfs(now, prv):
		for next in adj[now]:
#			print(f"{now=}, {next=}")
			if next == prv:
				continue
			ans[next] += ans[now]
			dfs(next, now)

	dfs(0, 0)
	print(*ans)

resolve()
### BUGGY CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K, Q = MAP()
A = [INT() for _ in range(Q)]
Score = [K]*N

for i in range(1, N+1):
  Score[i-1] -= Q - A.count(i)
  print("Yes" if Score[i-1] > 0 else "No")

### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K, Q = MAP()
A = [INT() for _ in range(Q)]
cnt = [0]*N

for n in A:
  cnt[n-1] += 1
  
for i in range(N):
  print("Yes" if K + cnt[i] -Q > 0 else "No")
### BUGGY CODE ###

n, q = map(int, input().strip().split(' '))
s = input()
ac = []
for i in range(n-1):
    if s[i-1:i+1] == 'AC':
        ac.append(i)
for i in range(q):
    num = 0
    l, r = map(int, input().strip().split(' '))
    print(sum((x >= l and x < r) for x in ac))

### FIXED CODE ###

n, q = map(int, input().strip().split(' '))
s = input()
ac = []
kazu = 0
for i in range(n-1):
    if s[i:i+2] == 'AC':
        kazu = kazu + 1
        ac.append(kazu)
    else:
        ac.append(kazu)
ac.append(0)
for i in range(q):
    num = 0
    l, r = map(int, input().strip().split(' '))
    print(ac[r-2]-ac[l-2])
### BUGGY CODE ###

tmp = list(map(int, input().split()))
x, y, a, b, c = tmp
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

def choice(li, n):
    d = []
    for i in range(n):
        m = max(li)
        d.append(m)
        li[li.index(m)] = -1
    return d

deli = []
red = choice(p, x)
green = choice(q, y)
deli.extend(red)
deli.extend(green)
while True:
    m = max(r)
    if m <= 0:
        break
    min_deli = min(deli)
    if m > min_deli:
        deli[deli.index(min_deli)] = m
        r[r.index(m)] = -1
    else:
        break

print(sum(deli))

### FIXED CODE ###

tmp = list(map(int, input().split()))
x, y, a, b, c = tmp
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort()
q.sort()
p = p[a-x:]
q = q[b-y:]

p.extend(q)
p.extend(r)
p.sort()
print(sum(p[len(p)-x-y:]))
### BUGGY CODE ###

N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[0 for i in range(N)]
for i in range(1,N):
    dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-K),i))
print(dp[N-1])                      
                      
                      
                  

### FIXED CODE ###

N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*N
for i in range(1,N):
    dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-K),i))
print(dp[N-1])
### BUGGY CODE ###

q=int(input())
import math
def is_prime(n):
    if n==1:return False
    for k in range(2,int(math.sqrt(n))+1):
        if n%k==0:
            return False
    return True
ko=[]
for i in range(1,10**5,2):
    if is_prime((i+1)//2)==True:
        if is_prime(i)==True:
            ko.append(i)
        
for i in range(q):
    l,r=map(int,input().split())
    s=l
    count=0
    while s<=r:
        if s in ko:
            count+=1
        s+=2
    print(count)

### FIXED CODE ###

q=int(input())
import math
import numpy as np
def is_prime(n):
    if n==1:return False
    for k in range(2,int(math.sqrt(n))+1):
        if n%k==0:
            return False
    return True
def is_is_prime(n):
    an=0
    if is_prime((n+1)//2)==True:
        if is_prime(n)==True:
            an=1
    return an
ko=[]
for i in range(1,10**5,2):
    ko.append(is_is_prime(i))

koko=np.cumsum(ko)

for i in range(q):
    l,r=map(int,input().split()) 
    if l==1:
        ans=koko[(r-1)//2]-koko[(l-1)//2]
    else:
        ans=koko[((r-1)//2)]-koko[((l-1)//2)-1]
    print(ans)
### BUGGY CODE ###

from collections import defaultdict, deque
n,m = list(map(int, input().split()))

d = defaultdict(set)

for _ in range(m):
    
    a,b = list(map(int, input().split()))
    d[a].add(b)
    d[b].add(a)
    
visited = set()

def dfs(node):
    
    c = 0
    stack = deque([node])
    s = set()
    while stack:
        n = stack.popleft()
        c += 1
        visited.add(n)
        s.add(n)
        for i in d[n]:
            if i not in visited:
                stack.append(i)
                
    return len(s)
    

ans = 1

for key in list(d.keys()):
    if key not in visited:

        c = dfs(key)
        ans = max(ans, c)
        


print(ans)
        

### FIXED CODE ###

from collections import defaultdict, deque
n,m = list(map(int, input().split()))

d = defaultdict(set)

for _ in range(m):
    
    a,b = list(map(int, input().split()))
    d[a].add(b)
    d[b].add(a)
    
visited = set()

def dfs(node):
    
    c = 0
    stack = deque([node])
    visited.add(node)
    while stack:
        n = stack.popleft()
        c+=1
        for i in d[n]:
            if  i not in visited:
                visited.add(i)
                stack.append(i)
                
    return c
    

ans = 1

for key in list(d.keys()):
    if key not in visited:

        c = dfs(key)
        ans = max(ans, c)
        


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

k=int(input())
q=[i for i in range(1,10)]
ans=0
for i in range(k):
    ans=q.pop(0)
    p=10*ans+int(str(ans)[-1])
    if(p%10!=0):q.append(p-1)
    q.append(p)
    if(p%10!=9):q.append(p+1)

print(ans)

### FIXED CODE ###

k=int(input())
q=[i for i in range(1,10)]
ans=0
c=0
for i in range(k):
    ans=q.pop(0)
    p=10*ans+int(str(ans)[-1])
    if(p%10!=0):q.append(p-1)
    q.append(p)
    if(p%10!=9):q.append(p+1)
    if(i+len(q)>k):break
    c+=1
for i in range(k-c-1):
    ans=q.pop(0)

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

s = input()
n = len(s)
i = 0
while i < n:
  if s[i] == "C":
    break
i += 1
while i < n:
  if s[i] == "F":
    print("Yes")
    exit()
print("No")

### FIXED CODE ###

s = input()
n = len(s)
i = 0
while i < n:
  if s[i] == "C":
    break
  i += 1
while i < n:
  if s[i] == "F":
    print("Yes")
    exit()
  i += 1
print("No")
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
b = list()
for i in range(n):
    if(i==0):
        b.append(a[i])
    elif(i%2==1):
        b.append(a[i])
    else:
        b.insert(0,a[i])
if(i%2==1):
    b.reverse()
for i in b:
    print(i,end=' ')

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = list()
c = list()
for i in range(n):
    if(i==0):
        b.append(a[i])
    elif(i%2==1):
        b.append(a[i])
    else:
        c.append(a[i])
c.reverse()
c = c + b
if(i%2==1):
    c.reverse()
for i in c:
    print(i,end=' ')
### BUGGY CODE ###

import copy

n, k, c = map(int, input().split())
s = list(input())

tmp = copy.deepcopy(s)
wait = 0
last_day = k
count = set()

for num, i in enumerate(tmp):
    if wait>0:
        wait -= 1
        continue
    if i == 'o':
        s[num] = 'a'
        count.add(num)
        wait = c
        last_day -= 1
        if last_day == 0:
            break

count2 = set()
last_day = k
wait = 0
for num, i in enumerate(reversed(tmp)):
    if wait>0:
        wait -= 1
        if i == 'a':
            s[num] = 'o'
        continue
    if i == 'o' or i == 'a':
        count2.add(n - num - 1)
        wait = c
        last_day -= 1
        if last_day == 0:
            break

count = count & count2
# print(count)        
ans = []    
for j in count:
    if s[j] =='o':
        continue
    wait = 0
    tmp = copy.deepcopy(s)
    last_day = k
    tmp[j] = 'x'
    for num, i in enumerate(tmp):
        if wait>0:
            if i == 'a':
                tmp[num] = 'o'
            wait -= 1
            continue
        if i == 'o' or i == 'a':
            wait = c
            last_day -= 1
            if last_day == 0:
                break
    if last_day > 0:
        ans.append(j+1)
    else:
        s = copy.deepcopy(tmp)
        
for i in ans:
    print(i)

### FIXED CODE ###

import copy

n, k, c = map(int, input().split())
s = list(input())

tmp = copy.deepcopy(s)
wait = 0
last_day = k
count = set()

for num, i in enumerate(tmp):
    if wait>0:
        wait -= 1
        continue
    if i == 'o':
        count.add(num)
        wait = c
        last_day -= 1
        if last_day == 0:
            break

tmp = copy.deepcopy(s)
wait = 0
last_day = k
count2 = set()
for num, i in enumerate(reversed(tmp)):
    if wait>0:
        wait -= 1
        continue
    if i == 'o':
        count2.add(n - num - 1)
        wait = c
        last_day -= 1
        if last_day == 0:
            break

count = list(count)
count2 = list(count2)
count.sort()
count2.sort()
ans = []
for i in range(len(count)):
    if count[i]==count2[i]:
        ans.append(count[i]+1)

for i in ans:
    print(i)
### BUGGY CODE ###

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

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

a_sorted = sorted(A, key=lambda x: -x)

circle = [a_sorted[0]]
ans = 0
for a in a_sorted:
    tmp = 0
    tmp_idx = -1
    for i in range(len(circle) - 1):
        cand = min(circle[i], circle[i + 1])
        if cand > tmp:
            tmp = cand
            tmp_idx = i
    ans += tmp
    circle.insert(tmp_idx + 1, a)

print(ans)


### FIXED CODE ###

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

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

a_sorted = sorted(A, key=lambda x: -x)

circle = [a_sorted[0]]
ans = 0
for idx, a in enumerate(a_sorted[1:]):
    ans += circle[idx]
    circle.extend([a, a])

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

import sys
input = sys.stdin.readline
H,W=map(int,input().split())
a = [[] for _ in range(H)]
for i in range(H):
    a[i] = list(map(int, input().split()))
b = [[] for _ in range(H)]
for i in range(H):
    b[i] = list(map(int, input().split()))
#print(a)
#print(b)
for i in range(H):
    for j in range(W):
        a[i][j] =abs(a[i][j]-b[i][j])
#print(a)
dp = [[set() for _ in range(W)] for _ in range(H)]
dp[0][0].add(a[0][0])
for i in range(H):
    for j in range(W):
        t = a[i][j]
        tmp = set()
        if i!=0:
            for k in dp[i-1][j]:
                tmp.add(abs(k+t))
                tmp.add(abs(k-t))
        if j!=0:
            for k in dp[i][j-1]:
                tmp.add(abs(k+t))
                tmp.add(abs(k-t))
        if i>0 or j>0:
            dp[i][j] = tmp
        #print(tmp)
#print(dp[H-1][W-1])
ls = list(dp[H-1][W-1])
#res = np.abs(np.asarray(ls)).argmin()
print(min(ls))


### FIXED CODE ###

import sys
input = sys.stdin.readline
H,W=map(int,input().split())
a = [[] for _ in range(H)]
for i in range(H):
    a[i] = list(map(int, input().split()))
b = [[] for _ in range(H)]
for i in range(H):
    b[i] = list(map(int, input().split()))

for i in range(H):
    for j in range(W):
        a[i][j] =abs(a[i][j]-b[i][j])

dp = [[set() for _ in range(W)] for _ in range(H)]
dp[0][0].add(a[0][0])
for i in range(1,H):
    t = a[i][0]
    tmp = set()
    for k in dp[i-1][0]:
        tmp.add(k+t)
        tmp.add(abs(k-t))
    dp[i][0] = tmp
for j in range(1,W):
    t = a[0][j]
    tmp = set()
    for k in dp[0][j-1]:
        tmp.add(k+t)
        tmp.add(abs(k-t))
    dp[0][j] = tmp
for i in range(1,H):
    for j in range(1,W):
        t = a[i][j]
        tmp = set()
        for k in (dp[i-1][j] | dp[i][j-1]):
            tmp.add(k+t)
            tmp.add(abs(k-t))
        dp[i][j] = tmp
        dp[i-1][j-1] = set()

ls = list(dp[H-1][W-1])
print(min(ls))
### BUGGY CODE ###

A,B,Q=map(int,input().split())
s=[]
t=[]
for i in range(A):
  s.append(int(input()))
for i in range(B):
  t.append(int(input()))
for i in range(Q):
  x=int(input())
  j=0
  while j<A:
    if x-s[j]>0:
      j+=1
    else:
      break
  if j==0:
    kouhoA=[s[j]]
  elif j==A:
    kouhoA=[s[j-1]]
  else:
    kouhoA=[s[j],s[j-1]]
  k=0
  while k<B:
    if x-t[k]>0:
      k+=1
    else:
      break
  if k==0:
    kouhoB=[t[k]]
  elif k==B:
    kouhoB=[t[k-1]]
  else:
    kouhoB=[t[k],t[k-1]]
  if len(kouhoA)==1:
    if len(kouhoB)==1:
      ans=min([abs(x-kouhoA[0])+abs(kouhoA[0]-kouhoB[0]),abs(x-kouhoB[0])+abs(kouhoB[0]-kouhoA[0])])
    else:
      ans=min([abs(x-kouhoA[0])+abs(kouhoA[0]-kouhoB[0]),abs(x-kouhoB[0])+abs(kouhoB[0]-kouhoA[0]),abs(x-kouhoA[0])+abs(kouhoA[0]-kouhoB[1]),abs(x-kouhoB[1])+abs(kouhoB[1]-kouhoA[0])])
  else:
    if len(kouhoB)==1:
      ans=min([abs(x-kouhoA[0])+abs(kouhoA[0]-kouhoB[0]),abs(x-kouhoB[0])+abs(kouhoB[0]-kouhoA[0]),abs(x-kouhoA[1])+abs(kouhoA[1]-kouhoB[0]),abs(x-kouhoB[0])+abs(kouhoB[0]-kouhoA[1])])
    else:
      ans=min([abs(x-kouhoA[0])+abs(kouhoA[0]-kouhoB[0]),abs(x-kouhoB[0])+abs(kouhoB[0]-kouhoA[0]),abs(x-kouhoA[1])+abs(kouhoA[1]-kouhoB[1]),abs(x-kouhoB[1])+abs(kouhoB[1]-kouhoA[1]),abs(x-kouhoA[1])+abs(kouhoA[1]-kouhoB[0]),abs(x-kouhoB[0])+abs(kouhoB[0]-kouhoA[1]),abs(x-kouhoA[0])+abs(kouhoA[0]-kouhoB[1]),abs(x-kouhoB[1])+abs(kouhoB[1]-kouhoA[0])])
  print(ans)

### FIXED CODE ###

import bisect
A,B,Q=map(int,input().split())
s=[]
t=[]
for i in range(A):
  s.append(int(input()))
for i in range(B):
  t.append(int(input()))
for i in range(Q):
  x=int(input())
  j=bisect.bisect_left(s,x)
  if j==0:
    kouhoA=[s[j]]
  elif j==A:
    kouhoA=[s[j-1]]
  else:
    kouhoA=[s[j],s[j-1]]
  k=bisect.bisect_left(t,x)
  if k==0:
    kouhoB=[t[k]]
  elif k==B:
    kouhoB=[t[k-1]]
  else:
    kouhoB=[t[k],t[k-1]]
  if len(kouhoA)==1:
    
    if len(kouhoB)==1:
      a=abs(kouhoA[0]-kouhoB[0])
      ans=min([abs(x-kouhoA[0])+a,abs(x-kouhoB[0])+a])
    else:
      u=abs(x-kouhoA[0])
      a=abs(kouhoA[0]-kouhoB[0])
      b=abs(kouhoA[0]-kouhoB[1])
      ans=min([u+a,abs(x-kouhoB[0])+a,u+b,abs(x-kouhoB[1])+b])
  else:
    if len(kouhoB)==1:
      a=abs(kouhoA[0]-kouhoB[0])
      c=abs(kouhoB[0]-kouhoA[1])
      v=abs(x-kouhoB[0])
      ans=min([abs(x-kouhoA[0])+a,v+a,abs(x-kouhoA[1])+c,v+c])
    else:
      u=abs(x-kouhoA[0])
      a=abs(kouhoA[0]-kouhoB[0])
      b=abs(kouhoA[0]-kouhoB[1])
      c=abs(kouhoB[0]-kouhoA[1])
      d=abs(kouhoA[1]-kouhoB[1])
      v=abs(x-kouhoB[0])
      w=abs(x-kouhoA[1])
      y=abs(x-kouhoB[1])
      ans=min([u+a,v+a,w+d,y+d,w+c,v+c,u+b,y+b])
  print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
port = list(map(int, input().split()))
visited = [1]
current = 1

t = k

while port[current-1] not in visited and t > 0:
    visited.append(port[current-1])
    current = port[current-1]
    t -= 1

if t > 0:
    s = visited.index(port[current-1])
    bubun = visited[s:]
    g = (k-s) % len(bubun)
    print(bubun[g])
else:
    print(current)


### FIXED CODE ###

n, k = map(int, input().split())
port = list(map(int, input().split()))
visited = [1]
flag = [False for i in range(n)]
current = 1

t = k

while flag[port[current-1]-1] == False and t > 0:
    visited.append(port[current-1])
    flag[port[current-1]-1] = True
    current = port[current-1]
    t -= 1

if t > 0:
    s = visited.index(port[current-1])
    bubun = visited[s:]
    g = (k-s) % len(bubun)
    print(bubun[g])
else:
    print(current)
### BUGGY CODE ###

import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

S = input().rstrip()

dp = [[0] * 13 for _ in range(len(S)+1)]
dp[0][0] = 1

#print(dp)

for i in range(len(S)):
	for j in range(13):
		if S[i]=='?':
			for d in range(10):
				nj = (j*10+d)%13
				dp[i+1][nj] += dp[i][j]
		else:
			nj = (j*10+int(S[i]))%13
			dp[i+1][nj] += dp[i][j]

#print(dp)
print((dp[len(S)][5])%(10**9+7))

### FIXED CODE ###

import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

S = input().rstrip()

dp = [[0] * 13 for _ in range(len(S)+1)]
dp[0][0] = 1

#print(dp)

for i in range(len(S)):
	for j in range(13):
		if S[i]=='?':
			for d in range(10):
				nj = (j*10+d)%13
				dp[i+1][nj] += dp[i][j]
		else:
			nj = (j*10+int(S[i]))%13
			dp[i+1][nj] += dp[i][j]
	for j in range(13):
		dp[i+1][j] %= (10**9+7)

#print(dp)
print(dp[len(S)][5])