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



n = int(input())
a = [int(input()) for i in range(n)]
sorted_a = sorted(a)

for i in range(n):
  cal_a = sorted_a.copy()
  cal_a.remove(a[i])
  print(cal_a[-1])

### FIXED CODE ###



n = int(input())
a = [int(input()) for i in range(n)]
a_sort = sorted(a)
amax = a_sort[-1]
asmas = a_sort[-2]

for i in range(n):
  if a[i] == amax:
    print(asmas)
  else:
    print(amax)
### BUGGY CODE ###

n, m =  map(int, input().split())
plist=[]
ylist = []
n0list=[]
for i in range(m):
    p, y =  map(int, input().split())
    plist.append(p)
    ylist.append(y)
    n0list.append(1)
    for j in range(i):
        if p == plist[j]:
            if y > ylist[j]:
                n0list[i] = n0list[i]+1
            else:
                n0list[j] = n0list[j]+1
for i in range(m):
    num = str(plist[i]*(10**6)+n0list[i])
    while len(num) < 12:
        num = '0' + num
    print(num)

### FIXED CODE ###

import sys
n,m = map(int, sys.stdin.readline().rstrip("\n").split())
city = {}
yton = {}
for i in range(m):
    p,y = map(int, sys.stdin.readline().rstrip("\n").split())
    if p not in city.keys():
        city[p] = []
        city[p].append(y)
        yton[y] = i
    else:
        city[p].append(y)
        yton[y] = i
ans = [None]*m
for p in city.keys():
    city[p].sort()
    for i,y in enumerate(city[p]):
        ans[yton[y]] = str(p*(10**6)+i+1).zfill(12)
print(*ans, sep = '\n')
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**5)
from collections import defaultdict

n = int(input())
e = [[] for i in range(n)]
for i in range(1,n):
    x = int(input())
    e[x-1].append(i)

def dfs(x):
    count = len(e[x])
    if count == 0:
        return 0
    d = defaultdict(int)
    ma = 0
    for nex in e[x]:
        v = dfs(nex)
        d[v] += 1
        ma = max(ma,v)
    now = count
    bef = 0
    for v in range(ma,-1,-1):
        if d[v] > 0:
            bef += d[v]
            now = max(now,bef+v)
    return now

print(dfs(0))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5)
from collections import defaultdict

n = int(input())
e = [[] for i in range(n)]
for i in range(1,n):
    x = int(input())
    e[x-1].append(i)

def dfs(x):

    count = len(e[x])
    if count == 0:
        return 0
    d = defaultdict(int)
    ma = 0
    s = set()
    for nex in e[x]:
        v = dfs(nex)
        d[v] += 1
        s.add(v)
        ma = max(ma,v)
    now = count
    bef = 0
    for v in sorted(list(s),reverse=True):
        bef += d[v]
        now = max(now,bef+v)
    return now

print(dfs(0))
### BUGGY CODE ###

import math

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

X = {}
for i in range(2, M):
  if M == 1:
    break
  while True:
    if M % i == 0:
      if i in X:
        X[i] = X[i] + 1
      else:
        X[i] = 1
      M //= i
    else:
      break

def cmb(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;
       
sum = 1
for i in X.values():
  sum = (sum * cmb(i + N - 1, i) % 1000000007) % 1000000007
  
  
print(sum)

### FIXED CODE ###

import math
import copy

####################
def prime_decomposition(n):
  i = 2
  X = {}
  while i * i <= n:
    while n % i == 0:
      n /= i
      if i in X:
        X[i] = X[i] + 1
      else:
        X[i] = 1
    i += 1
  if n > 1:
    X[n] = 1
  return X

def cmb(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;

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

X = prime_decomposition(M)
       
sum = 1
for i in X.values():
  sum = (sum * cmb(i + N - 1, i) % 1000000007) % 1000000007
  
print(sum)
### BUGGY CODE ###

r,g,b,n=map(int,input().split())
p=0
i,j=0,0
while j < n+1:
    k=i*r+j*g
    if (n-k)%b==0 and k <= n:
        #print(i,j,n-k)
        p+=1
    i+=1
    if i>n:
        i=0
        j+=1
print(p)

### FIXED CODE ###

r,g,b,n=map(int,input().split())
p=0
i,j=0,0
while j < n+1:
    k=i*r+j*g
    if (n-k)%b==0 and k <= n:
        #print(i,j,n-k)
        p+=1
    i+=1
    if i>n:
        i=0
        j+=1
print(p)
### BUGGY CODE ###

H, W = map(int, input().split())

#A = [input() for _ in range(H)]

data = []

for y in range(H):
    for x, v in enumerate(input()):
        if v == '#':
            data.append([y, x, [], 0])

inf = H * W + 10
ans = [[inf for _ in range(W)] for __ in range(H)]

for v in data:
    ans[v[0]][v[1]] = 0

def check(destination, origin):
    return [destination[0], destination[1]] not in origin[2]

def cnt_update(ans, v):
    ans[v[0], v[1]] = v[3] + 1

while len(data):
    v = data.pop(0)
    v[2].append([v[0], v[1]])

    if v[1] - 1 >= 0 and ans[v[0]][v[1] - 1] > v[3] + 1:
        v_left = [v[0], v[1] - 1, v[2], v[3] + 1]
        if check(v_left, v):
            ans[v_left[0]][v_left[1]] = v_left[3]
            data.append(v_left)
    if v[1] + 1 <= W - 1 and ans[v[0]][v[1] + 1] > v[3] + 1:
        v_right = [v[0], v[1] + 1, v[2], v[3] + 1]
        if check(v_right, v):
            ans[v_right[0]][v_right[1]] = v_right[3]
            data.append(v_right)
    if v[0] - 1 >= 0 and ans[v[0] - 1][v[1]] > v[3] + 1:
        v_up = [v[0] - 1, v[1], v[2], v[3] + 1]
        if check(v_up, v):
            ans[v_up[0]][v_up[1]] = v_up[3]
            data.append(v_up)
    if v[0] + 1 <= H - 1 and ans[v[0] + 1][v[1]] > v[3] + 1:
        v_down = [v[0] + 1, v[1], v[2], v[3] + 1]
        if check(v_down, v):
            ans[v_down[0]][v_down[1]] = v_down[3]
            data.append(v_down)

print(max([a for aa in ans for a in aa]))

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
data = deque()

for y in range(H):
    for x, v in enumerate(input()):
        if v == '#':
            data.append((y, x))

ans = [[-1 for _ in range(W)] for __ in range(H)]

for v in data:
    ans[v[0]][v[1]] = 0

"""
BFSまとめ

0. 
現在位置、履歴、アクション数の3要素が必要.
処理をLIFOでなく、FIFOでやる
そのため、collection.dequeを使う
更にソートしつつ、FIFOしたい場合は、heapqを使う

1. 
更新する, アクション数を加算する

2. 
条件を一致しているか、履歴に入っていないかを確認

3. 
popをループ
"""

d = 0
while len(data):
    y, x = data.popleft()
    d = ans[y][x]

    for i, j in ((-1, 0), (1, 0), (0, -1), (0, 1)):
        new_y = y + i
        new_x = x + j
        if new_y < 0 or H <= new_y or new_x < 0 or W <= new_x:
            continue
        if ans[new_y][new_x] == -1:
            ans[new_y][new_x] = d + 1
            data.append((new_y, new_x))

print(max([a for aa in ans for a in aa]))
### BUGGY CODE ###

n = int(input())
t,a = 0,0
for i in range(n):
    tt,aa = map(int,input().split())
    p,q = tt,aa
    while p<t or q<a:
        p += tt
        q += aa
    t,a = p,q
print(t+a)


### FIXED CODE ###

n = int(input())
a,b = 1,1
for i in range(n):
    T,A = map(int,input().split())
    N = max((T+a-1)//T,(A+b-1)//A)
    a,b = N*T,N*A
print(a+b)
### BUGGY CODE ###

import itertools

ans_list = []

while 1:
    ab = raw_input()
    if ab != "":
        a, b= map(int, ab.split())
    else:
        for s in ans_list:
            print s
        break
    GCD = a * b
    LCM = 0
    # GCD
    for i, j in itertools.product(range((a if a > b else b) / 2), repeat=2):
        if a * (i+1) == b * (j+1) and GCD > a * (i+1):
            GCD = a * (i+1)
    # LCM
    for i in range(a if a > b else b, 1, -1):
        if a % i == 0 and b % i == 0:
            LCM = i
            break
    ans_list.append(str(GCD) + " " + str(LCM))

### FIXED CODE ###

def get_gcd(a,b):
	if a > b: a, b = b, a
	if b % a == 0:
		return a
	else:
		return get_gcd(a, b % a)

def get_lcm(a,b,g):
	return a * b / g

while True:
	try:
		a,b = map(int, sorted(raw_input().split()))
		GCD = get_gcd(a,b)
		LCM = get_lcm(a,b,GCD)
		print "{} {}".format(GCD, LCM)
	except EOFError:
		break
### BUGGY CODE ###

N,Q=map(int,input().split())
S=input()
for i in range(Q):
    l,r=map(int,input().split())
    print(S[l-1:r].count("AC"))

### FIXED CODE ###

N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[l-1])
### BUGGY CODE ###

N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
import heapq
A.reverse()

count = 0
for i in range(N):
  if A:
    count += 1
    num_temp = A[0]
    while num_temp >= 0:
      try:
      	A.remove(num_temp)
      	num_temp -= 1
      except ValueError:
        num_temp-=1
  else:
    break

print(count)
  
  

### FIXED CODE ###

def bisect_right_reverse(a, x):
    '''
    reverseにソートされたlist aに対してxを挿入できるidxを返す。
    xが存在する場合には一番右側のidx+1となる。
    '''
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

def main():
  N = int(input())
  ans = 1
  lis_min = [int(input())]
  for i in range(N-1):
    a = int(input())
    index = bisect_right_reverse(lis_min, a)
    if index != len(lis_min):
      lis_min[index] = a
    else:
      ans += 1
      lis_min.append(a)
  print(ans)
if __name__ == "__main__":
  main()
### BUGGY CODE ###

import bisect
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
for i in range(m):
    tmp_max = a.pop()
    bisect.insort(a, tmp_max // 2)
print(sum(a))

### FIXED CODE ###

import math
import heapq

n, m = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x:x*(-1), A))
heapq.heapify(A)
for i in range(m):
    min = (-1)*((-1)*(heapq.heappop(A))//2)
    heapq.heappush(A, min)


print(int(sum(A))*(-1))
### BUGGY CODE ###

N,M = map(int,input().split())
l,B_s,B_l = [],[],[]
for i in range(M):
    a,b = map(int,input().split())
    if a == 1 :
        if b < N:
            B_s.append(b)
        elif b > N:
            B_l.append(b)        
    l.append([a,b])
for e in l:
    if e[0] in B_s and e[1] == N:
        print("POSSIBLE")
        break
    elif e[1] in B_l and e[0] == N:
        print("POSSIBLE")
        break
    elif e == l[-1]:
        print("IMPOSSIBLE")

### FIXED CODE ###

N,M = map(int,input().split())
l_s,l_l,B_s,B_l = [],[],[],[]
for i in range(M):
    a,b = map(int,input().split())
    if a == 1 :
        if b < N:
            B_s.append(b) #Nより小さい
        elif b > N:
            B_l.append(b) #Nより大きい
    if a == N:
        l_l.append(b) #Nより大きい
    elif b == N:
        l_s.append(a) #Nより小さい
common_1 = len(list(set(l_s) & set(B_s)))
common_2 = len(list(set(l_l) & set(B_l)))
if common_1 > 0 or common_2 > 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
### BUGGY CODE ###

n, w = map(int, input().split())
wv = []
for i in range(n):
    wv_ = list(map(int, input().split()))
    wv.append(wv_)
dp = [0]*(w+1)
for i in range(n):
    for j in range(w, wv[i][0]-1, -1):
        dp_ = dp[j - wv[i][0]] + wv[i][1]
        if dp[j] < dp_:
            dp[j] = dp_
print(max(dp))

### FIXED CODE ###

n, w = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]
dp = [[0]*(w+1) for _ in range(n+1)]
for i in range(n):
    w_, v_ = wv[i]
    for j in range(w+1):
        if j < w_:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j-w_]+v_, dp[i][j])
print(dp[n][w])
### BUGGY CODE ###

from heapq import heappop,heappush

def main(a,b):
    for i in range(n):
        if b[i]<=a[i]:
            pass
        else:
            print(-1)
            exit()
    pq=[]
    [heappush(pq,[-x,i]) for i,x in enumerate(a)]
    ans=0
    while pq:
        v,i=heappop(pq)
        v=-v
        vv=v
        v-=b[i]
        tmp=a[(i-1)%n]+a[(i+1)%n]
        ans+=v//tmp
        v%=tmp
        v+=b[i]
        a[i]=v
        if v==b[i]:continue
        elif vv<=v or v<b[i]:
            print(-1)
            exit()
        heappush(pq,[-v,i])
    print(ans)
if __name__=='__main__':
    n=int(input())
    b=list(map(int,input().split()))
    a=list(map(int,input().split()))
    main(a,b)


### FIXED CODE ###

def main(n,a,b):
    ans=0
    while True:
        cnt=0
        for i in range(n):
            m=a[(i-1)%n]+a[(i+1)%n]
            if m<a[i] and b[i]<a[i]:
                a[i]-=b[i]
                cnt+=a[i]//m
                a[i]%=m
                a[i]+=b[i]
        if cnt==0:break
        ans+=cnt
    if a==b:
        print(ans)
    else:
        print(-1)
if __name__=='__main__':
    n=int(input())
    b=list(map(int,input().split()))
    a=list(map(int,input().split()))
    main(n,a,b)
### BUGGY CODE ###

S = input()
Q = int(input())


condition = [list(map(str, input().split())) for i in range(Q)]

for i in condition:
    
    if i[0] == '1':
        S = ''.join(list(reversed(S)))
    elif i[0] == '2':
        if i[1] == '1':
            S = i[2] + S
        elif i[1] == '2':
            S = S + i[2]
print(S)


### FIXED CODE ###

from collections import deque
d = deque()

S = input()
Q = int(input())
d.extend(S)




front = True

for i in range(Q):
    inp = input().split()
    if inp[0] == '1':
        front = not front
    else:
        F = int(inp[1])
        C = inp[2]
        if F == 1:
            if front:
                d.appendleft(C)
            else:
                d.append(C)
        elif F == 2:
            if front:
                d.append(C)
            else:
                d.appendleft(C)

if not front:
    d.reverse()

d_list = list(d)
str = "".join(d_list)

print(str)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
h, w = map(int, input().split())
grid = []
bias_inf = 2000
for i in range(h):
    k = list(map(int, input().split()))
    grid.append(k)
for i in range(h):
    k = list(map(int, input().split()))
    for j in range(w):
        grid[i][j] = abs(grid[i][j] - k[j])

dp = [[[False for i in range(-bias_inf,bias_inf)] for j in range(w)] for k in range(h)]
dp[0][0][0 - grid[0][0]] = True
dp[0][0][0 + grid[0][0]] = True
for i in range(h):
    for j in range(w):
        for k in range(-bias_inf,bias_inf):
            if i == h-1 and j == w-1:
                break
            if dp[i][j][k]:
                if i == h-1:
                    dp[i][j+1][k - grid[i][j+1]] = True
                    dp[i][j+1][k + grid[i][j+1]] = True
                elif j == w-1:
                    dp[i+1][j][k - grid[i+1][j]] = True
                    dp[i+1][j][k + grid[i+1][j]] = True
                else:
                    dp[i][j+1][k + grid[i][j+1]] = True
                    dp[i+1][j][k + grid[i+1][j]] = True
                    dp[i][j+1][k - grid[i][j+1]] = True
                    dp[i+1][j][k - grid[i+1][j]] = True
ans = bias_inf
for i in range(-bias_inf,bias_inf):
    if dp[-1][-1][i]:
        ans = min(ans, abs(i))
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
h, w = map(int, input().split())
grid = []
bias_inf = 2000
for i in range(h):
    k = list(map(int, input().split()))
    grid.append(k)
for i in range(h):
    k = list(map(int, input().split()))
    for j in range(w):
        grid[i][j] = abs(grid[i][j] - k[j])

dp = [[[0 for i in range(-bias_inf,bias_inf)] for j in range(w)] for k in range(h)]
dp[0][0][0 - grid[0][0]] = 1
dp[0][0][0 + grid[0][0]] = 1
for i in range(h):
    for j in range(w):
        for k in range(-bias_inf,bias_inf):
            if i == h-1 and j == w-1:
                break
            if dp[i][j][k]:
                if i != h-1 and j != w-1:
                    dp[i][j+1][k + grid[i][j+1]] = 1
                    dp[i+1][j][k + grid[i+1][j]] = 1
                    dp[i][j+1][k - grid[i][j+1]] = 1
                    dp[i+1][j][k - grid[i+1][j]] = 1
                elif j == w-1:
                    dp[i+1][j][k - grid[i+1][j]] = 1
                    dp[i+1][j][k + grid[i+1][j]] = 1
                else:
                    dp[i][j+1][k - grid[i][j+1]] = 1
                    dp[i][j+1][k + grid[i][j+1]] = 1
ans = bias_inf
for i in range(-bias_inf,bias_inf):
    if dp[-1][-1][i]:
        ans = min(ans, abs(i))
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
# coding=utf-8

import sys
import random

import functools


@functools.lru_cache(1000000)
def is_prime3(q, k=5):
    if q == 2:
        return True
    if q < 2 or q & 1 == 0:
        return False

    d = (q - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    for i in range(k):
        a = random.randint(1, q - 1)
        t = d
        y = pow(a, t, q)
        while t != q - 1 and y != 1 and y != q - 1:
            y = pow(y, 2, q)
            t <<= 1
        if y != q - 1 and t & 1 == 0:
            return False
    return True


q = int(sys.stdin.readline().strip())
for _ in range(q):
    l, r = sys.stdin.readline().strip().split(" ")
    l = int(l)
    r = int(r)
    ans = 0
    for i in range(l, r + 1, 2):
        if is_prime3(i) and is_prime3((i + 1) // 2):
            ans += 1
    print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
# coding=utf-8

import sys

import numpy as np

num_max = 100000
primes = np.asarray([True for _ in range(num_max + 1)])
for i in range(num_max + 1):
    if i == 0 or i == 1:
        primes[i] = False
    else:
        primes[i * 2::i] = False
primes = set(np.arange(num_max + 1)[primes])
like2017 = [1 if i in primes and (i + 1) // 2 in primes else 0 for i in range(num_max + 1)]
cumsum = np.cumsum(like2017)

q = int(sys.stdin.readline().strip())
for _ in range(q):
    l, r = sys.stdin.readline().strip().split(" ")
    l = int(l)
    r = int(r)
    print(cumsum[r] - cumsum[l - 1])
### BUGGY CODE ###

# https://atcoder.jp/contests/abc128/submissions/7097699
from bisect import bisect_left

n,q = map(int, input().split())
road = [list(map(int, input().split())) for i in range(n)]
road.sort(key=lambda x: x[2])
start = [int(input()) for i in range(q)]

skip = [-1]*q
ans = [-1]*q
for s,t,x in road:
    left = bisect_left(start, s-x)
    right = bisect_left(start, t-x)
    # [left, right)をxで埋める
    # すでに存在するところ(skipがあるところ)は飛ばす
    while left < right:
        if skip[left] == -1:
            ans[left] = x
            skip[left] = right
            left += 1
        else:
            left = skip[left]
print(*ans, sep="\n")

### FIXED CODE ###

import sys
input = sys.stdin.readline

class RangeUpdateQuery:
    def __init__(self, n):
        self.n0 = 2**(n-1).bit_length()
        self.INF = float("inf")
        self.data = [self.INF]*(2*self.n0-1)

    def update(self, l,r,v):
        l += self.n0
        r += self.n0
        while l < r:
            if r&1:
                r -= 1
                self.data[r-1] = v
            if l&1:
                self.data[l-1] = v
                l += 1
            l >>=1
            r >>=1

    def query(self, i):
        i += self.n0-1
        res = self.INF
        while i+1:
            if self.data[i] < res:
                res = self.data[i]
            i = ~-i//2
        return res

n,q = map(int, input().split())
start = [None]*q
se = set()

road = []
for i in range(n):
    s,t,x = map(int, input().split())
    road.append([x, x-t, x-s])
for i in range(q):
    d = int(input())
    start[i] = -d

start = start[::-1]

RUQ = RangeUpdateQuery(q)
road.sort(reverse=True)
from bisect import bisect_left,bisect_right
for i, (x, s, t) in enumerate(road):
    l = bisect_right(start, s)
    r = bisect_right(start, t)
    #print(x, (s,t), l, r)
    RUQ.update(l, r, x)

ans = []
for i in range(q):
    x = RUQ.query(i)
    if x == float("inf"):
        x = -1
    ans.append(x)
ans = ans[::-1]
print(*ans, sep="\n")
### BUGGY CODE ###

from itertools import accumulate

n, m, k = map(int, input().split())
(*a,) = accumulate(map(int, input().split()))
(*b,) = accumulate(map(int, input().split()))
a = (0,) + tuple(i for i in a if i <= k)
b = (0,) + tuple(i for i in b if i <= k)
ans = set()
for i in range(len(a)):
    tmp = k - a[i]
    for j in range(len(b) - 1, -1, -1):
        if b[j] <= tmp:
            ans.add(i + j)
            break
print(max(ans))

### FIXED CODE ###

from itertools import accumulate
from bisect import bisect

n, m, k = map(int, input().split())
(*a,) = accumulate(map(int, input().split()))
(*b,) = accumulate(map(int, input().split()))
a = (0,) + tuple(i for i in a if i <= k)
b = tuple(i for i in b if i <= k)
print(max(i + bisect(b, k - a[i]) for i in range(len(a))))
### BUGGY CODE ###

import fractions
mod = 10**9 + 7
n = int(input())
lst = list(map(int, input().split()))
koubai = lst[0]
for i in range(1, n):
    koubai = koubai*lst[i]//fractions.gcd(koubai, lst[i])

total = 0
for l in lst:
    b = koubai//l
    total += b
    total %= mod
print(total)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
lcm = a[0]

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

for i in range(1, n):
    lcm = lcm * a[i] // gcd(lcm, a[i])
mod = 10**9 + 7
ans = 0
for i in range(n):
    ans += lcm // a[i]
print(ans % mod)
### BUGGY CODE ###

n, m = map(int, input().split())
root = [[] for _ in range(n)]
adj = [-1 for _ in range(n)]
for _ in range(m):
  r,c = map(int, input().split())
  root[r-1].append(c-1)
  root[c-1].append(r-1)
  
visited = {0}
explor = [0]

while len(visited)!=n:
  tmp_explor = set()
  while explor:
    tmp = explor.pop()
    tmp_explor = tmp_explor.union(set(root[tmp]))
    visited = visited.union(set(root[tmp]))
    for i in root[tmp]:
      if adj[i]==-1:
        adj[i] = tmp
  explor = tmp_explor.copy()

print('Yes')
for i in adj[1:]:
  print(i+1)

### FIXED CODE ###

from collections import deque

n, m = map(int, input().split())
root = [[] for _ in range(n)]
adj = [-1 for _ in range(n)]
for _ in range(m):
  r,c = map(int, input().split())
  root[r-1].append(c-1)
  root[c-1].append(r-1)
  
explor = deque()
explor.append(0)

while explor:
  tmp = explor.popleft()
  for i in root[tmp]:
    if adj[i]==-1:
      adj[i] = tmp
      explor.append(i)

print('Yes')
for i in adj[1:]:
  print(i+1)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
tmp = 0
diffs = []
for i in range(N - 1):
    tmp += A[i]
    diffs.append(abs(sum(A) - tmp - tmp))
print(min(diffs))


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
tmp = 0
ans = 10 ** 10
Asum = sum(A)
for i in range(N - 1):
    tmp += A[i]
    a = abs((Asum - tmp) - tmp)
    if ans > a:
        ans = a
print(ans)
### BUGGY CODE ###

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

machi = 1
toutatu = []
while not machi in set(toutatu):
	toutatu.append(machi)
	machi = a[machi-1]
saigo = machi
num = toutatu.index(saigo)
unchi = toutatu[num:]
cnt = len(unchi)
num = toutatu.index(saigo)

if num > k:
	print(toutatu[k])
else:
	print(unchi[(k-num)%cnt])

### FIXED CODE ###

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

machi = 1
toutatu = []
pypyosoi = set()
while not machi in pypyosoi:
	toutatu.append(machi)
	pypyosoi.add(machi)
	machi = a[machi-1]

saigo = machi
num = toutatu.index(saigo)
unchi = toutatu[num:]
cnt = len(unchi)

if num > k:
	print(toutatu[k])
else:
	print(unchi[(k-num)%cnt])

#pypyが遅いのは自分のコードが悪いだけごめんねpypyちゃん