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

from math import sqrt
from fractions import gcd
from collections import defaultdict
from copy import deepcopy

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

def f(n):
    d = defaultdict(int)
    if n % 2 == 0:
        r = 0
        while n % 2 == 0:
            n //= 2
            r += 1
        d[2] = r
    for i in range(3,int(sqrt(n))+1,2):
        if n % i == 0:
            s = 0
            while n % i == 0:
                n //= i
                s += 1
            d[i] = s
    if n != 1:
        d[n] = 1
    return d

B = [f(A[i]) for i in range(N)]

lp = deepcopy(B[0])

for i in range(N-1):
    for j in list(set(B[i+1].keys()) | set(lp.keys())):
        lp[j] = max(B[i+1][j],lp[j])

ans = 0

for i in range(N):
    r = 1
    for j in list(lp.keys()):
        r = (r*pow(j,lp[j]-B[i][j],mod)) % mod
    ans = (ans + r) % mod

print(ans)

### FIXED CODE ###

def main():
    from math import sqrt
    from fractions import gcd
    from collections import defaultdict
    from copy import deepcopy

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

    p = [1] * (1001)
    P = []  # 1000までの素数表
    p[0] = p[1] = 0
    for x in range(2, int(sqrt(1000000)) + 1):
        if p[x]:
            P.append(x)
            for y in range(x * x, 1001, x):
                p[y] = 0

    B = [defaultdict(int) for i in range(N)]  # N個の数を素因数分解したもの
    lcm = defaultdict(int)  # N個の数のlcmを素因数分解したもの

    for i in range(N):
        for j in P:
            if A[i] % j == 0:
                while A[i] % j == 0:
                    A[i] //= j
                    B[i][j] += 1
            lcm[j] = max(lcm[j], B[i][j])
        if A[i] != 1:
            B[i][A[i]] = 1
            lcm[A[i]] = 1

    l = 1  # N個の数のlcm
    for i in lcm.keys():
        l = (l * pow(i, lcm[i], mod)) % mod

    ans = 0
    # l/A[i]の和を求めていく
    for i in range(N):
        r = l
        for j in list(B[i].keys()):
            r = (r * pow(j, mod - B[i][j] - 1, mod)) % mod
        ans = (ans + r) % mod

    print(ans)

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

import sys
from collections import deque


dx_list = [1, 0, -1, 0]
dy_list = [0, -1, 0, 1]
def bfs(h_len, w_len):
    max_cnt = 0
    while len(bfs_q)>0:
        u_list = bfs_q.popleft()
        h, w, cnt = u_list[0], u_list[1], u_list[2]
        max_cnt = max(max_cnt, cnt)
        for dx, dy in zip(dx_list, dy_list):
            x = w + dx
            y = h + dy
            if 0 <= x < w_len and 0 <= y < h_len and m[y][x] == 0:
                m[y][x] = 1
                bfs_q.append([y, x, cnt+1])
    return max_cnt


if __name__ == "__main__":
    input = sys.stdin.readline
    h_len, w_len = map(int, input().split())
    m = [[0]*w_len for _ in range(h_len)]
    a_list = []
    for _ in range(h_len):
        s = input()[:-1]
        a_list.append(s)
    bfs_q = deque([])
    for h, w_list in enumerate(a_list):
        for w, a in enumerate(w_list):
            if a == '#':
                m[h][w] = 1
                bfs_q.append([h, w, 0])
    ans = bfs(h_len, w_len)
    print(ans)
	

### FIXED CODE ###

def bfs(q_list):
    cnt = -1
    while q_list:
        cnt += 1
        new_q_list = []
        for h, w in q_list:
            if not m_list[h][w+1]:
                m_list[h][w+1] = True
                new_q_list.append((h, w+1))
            if not m_list[h+1][w]:
                m_list[h+1][w] = True
                new_q_list.append((h+1, w))
            if not m_list[h][w-1]:
                m_list[h][w-1] = True
                new_q_list.append((h, w-1))
            if not m_list[h-1][w]:
                m_list[h-1][w] = True
                new_q_list.append((h-1, w))
        q_list = new_q_list
    print(cnt)


if __name__ == "__main__":
    h_len, w_len = map(int, input().split())
    m_list = [[True for _ in range(w_len+2)]]
    for _ in range(h_len):
        m_list.append([True] + [s=='#' for s in input()] + [True])
    m_list.append([True for _ in range(w_len+2)])
    q_list = []
    for h in range(1, h_len+1):
        for w in range(1, w_len+1):
            if m_list[h][w]:
                q_list.append((h, w))
    bfs(q_list)
### BUGGY CODE ###

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

n = int(input())
s = input()

for m in range(n//2+1,0,-1):
    d = {}
    for l in range(n-m+1):
        ss = s[l:l+m]
        if ss not in d:
            d[ss] = l
        else:
            l2 = d[ss]
            if l2+m<=l:
                print(m)
                exit()
print(0)


### FIXED CODE ###

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

n = int(input())
s = input()

ok = 0
ng = n//2+1

while ng-ok>1:
    mid = (ok+ng)//2

    d = {}
    isOk = False
    for l in range(n-mid+1):
        ss = s[l:l+mid]
        if ss not in d:
            d[ss] = l
        else:
            l2 = d[ss]
            if l2+mid<=l:
                isOk = True
                break

    if isOk:
        ok = mid
    else:
        ng = mid

print(ok)
### BUGGY CODE ###

k,s=map(int,input().split())
ans=0
for i in range(k+1):
  for j in range(k+1):
    for l in range(k+1):
      if i+j+l==s:
        ans += 1
        break
print(ans)


### FIXED CODE ###

k,s=map(int,input().split())
from math import factorial
def c(n,r):
  return factorial(n)//factorial(n-r)//factorial(r)
ans=0
for x in range(k+1):
  for y in range(k+1):
    if 0<=s-x-y<=k:
      ans += 1
print(ans)
### BUGGY CODE ###

from collections import deque,defaultdict

N,X,Y = map(int,input().split())

L= [[1]]+[[i-1,i+1] for i in range(1,N-1)]+ [[N-2]]
L[X-1].append(Y-1)
L[Y-1].append(X-1)

def BFS(x,L):
  d=[-1 for _ in range(N)] #距離
  d[x]=0
  v=deque([x])
  
  while len(v)>0:
    a=v.popleft()
    for num in L[a]:
      if d[num]==-1:
        d[num]=d[a]+1
        v.append(num)
  return d

ans=defaultdict(int)

for j in range(N):
  tmp=BFS(j,L)
  #print(tmp)
  for num in tmp:
    ans[num] += 1
    
for k in range(1,N):
  if k in ans:
    print(ans[k]//2)
  else:
    print(0)


### FIXED CODE ###

N,X,Y=map(int,input().split())
cost=[[] for _ in range(N)]

for i in range(N-1):
  cost[i].append(i+1)
for j in range(1,N):
  cost[j].append(j-1)

cost[X-1].append(Y-1)
cost[Y-1].append(X-1)
#print(cost)

def bfs(v):
    d=[-1]*N
    d[v]=0
    q=[v]
    c=1
    while q:
        q1=[]
        for i in q:
            for j in cost[i]:
                if d[j]==-1:
                    d[j]=c
                    q1.append(j)
        q=q1
        c+=1
        #print(d,q)
    return d

d=dict()
for m in range(N):
  tmp=bfs(m)
  #print(tmp)
  for num in tmp:
    if num not in d:
      d[num]=1
    else:
      d[num] += 1
#print(d)

for z in range(1,N):
  if z in d:
    print(d[z]//2)
  else:
    print(0)
### BUGGY CODE ###

class UnionFind:
    #n個の要素を初期化
    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]
        self.rank = [0] * n
    
    #木の根を求める
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    
    #xとyの属する集合を併合
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    
    #xとyが同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    #要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]


N, K, L = map(int, input().split())
roads = [list(map(int, input().split())) for i in range(K)]
trains = [list(map(int, input().split())) for i in range(L)]

uf_road = UnionFind(N)
uf_train = UnionFind(N)

for road in roads:
    x, y = road
    uf_road.unite(x-1, y-1)

for train in trains:
    x, y = train
    uf_train.unite(x-1, y-1)

ans = []
for i in range(N):
    common = set(uf_road.members(i)) & set(uf_train.members(i))
    ans.append(len(common))

print(*ans)

### FIXED CODE ###

from collections import Counter

class UnionFind:
    #n個の要素を初期化
    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n)]
        self.rank = [0] * n
    
    #木の根を求める
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    
    #xとyの属する集合を併合
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    
    #xとyが同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    #要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]


N, K, L = map(int, input().split())
roads = [list(map(int, input().split())) for i in range(K)]
trains = [list(map(int, input().split())) for i in range(L)]

uf_road = UnionFind(N)
uf_train = UnionFind(N)

for road in roads:
    x, y = road
    uf_road.unite(x-1, y-1)

for train in trains:
    x, y = train
    uf_train.unite(x-1, y-1)

pairs = []
for i in range(N):
    pairs.append((uf_road.find(i), uf_train.find(i)))

cnt = Counter(pairs)

ans = [cnt[pair] for pair in pairs]
print(*ans)
### BUGGY CODE ###

import queue

def resolve():
    # ★get input
    h, w = map(int, input().split())

    grid = [["" for i in range(w)] for j in range(h)]

    for i in range(h):
        grid[i] = list(input())


    # ★exec
    # BFSにて最短経路を求める
    # 準備
    distance = [[-1 for i in range(w)] for j in range(h)]
    que = queue.Queue()

    # スタート地点の情報を設定
    # 多点スタートの設定
    for i in range(h):
        for j in range(w):
            if grid[i][j] == "#":
                que.put([i, j])
                distance[i][j] = 0

    # BFS開始
    while not que.empty():

        now = que.get()

        # 上下左右のマスを確認
        for move_y, move_x in ((1, 0), (-1, 0), (0, 1), (0, -1)):

            # 盤の範囲外なら何もしない
            target = [now[0] + move_y, now[1] + move_x]
            if not h > target[0] >= 0 or not w > target[1] >= 0:
                continue

			# 距離が設定済みなら何もしない
            if not distance[target[0]][target[1]] == -1:
                continue

            # 黒塗りされているなら何もしない
            # if grid[target[0]][target[1]] == '#':
            #    continue

            # キューに追加
            que.put(target)

            # 最短距離を設定
            distance[target[0]][target[1]] = distance[now[0]][now[1]] + 1

    # 距離が最大の点 = 答えになる。
    ans = 0
    for i in range(h):
        ans = max(ans, max(distance[i]))

    print(ans)


if __name__ == "__main__":
    resolve()


### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
grid = [input() for i in range(H)]

# 初期の黒('#')の位置からの距離
dist = [[-1]*W for _ in range(H)]

# '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append((h, w))
            dist[h][w] = 0

def bfs(black_cells, dist):
    """
    BFSを用いて、全マス目を黒くする回数を求める

    Args:
        black_cells: 「開始時の黒マス」の座標が入ったキュー（複数座標あり）
        dist: 「開始時の黒マス」からの距離の入ったリスト  [[-1, -1, 0], ...]
        　　　（白マスの初期値は0）

    Returns:
        g: 操作を繰り返した数
    """
    d = 0
    while black_cells:
        # キューとして使うのでpop()ではなくpopleft()
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:  # セルが白('.')であるのと同義
                dist[new_h][new_w] = d+1
                black_cells.append((new_h, new_w))
    return d

d = bfs(black_cells, dist)
print(d)
### BUGGY CODE ###

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

road = {}
for i, h in zip(range(1, N + 1, 1), H):
    road[i] = {
        "high": h,
        "connect": [],
        "good": True
    }

for i in range(M):
    Ai, Bi = map(int, input().split())

    road[Ai]["connect"] = list(set(road[Ai]["connect"] + [Bi]))
    if road[Ai]["high"] <= road[Bi]["high"]:
        road[Ai]["good"] = False

    road[Bi]["connect"] = list(set(road[Bi]["connect"] + [Ai]))
    if road[Bi]["high"] <= road[Ai]["high"]:
        road[Bi]["good"] = False

print(len([1 for i in range(1, N + 1, 1) if road[i]["good"] is True]))


### FIXED CODE ###

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

cnt = N
road = {}
for i, h in zip(range(1, N + 1, 1), H):
    road[i] = {
        "high": h,
        "good": True
    }

for i in range(M):
    Ai, Bi = map(int, input().split())

    if road[Ai]["good"] is True and road[Ai]["high"] <= road[Bi]["high"]:
        road[Ai]["good"] = False
        cnt -= 1

    if road[Bi]["good"] is True and road[Bi]["high"] <= road[Ai]["high"]:
        road[Bi]["good"] = False
        cnt -= 1

print(cnt)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
MAX = 10 ** 6 + 10

one = a.count(1)
if one > 0:
  if one == 1:
    print(1)
  else:
    print(0)
  exit(0)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
m = [0] * MAX
for i in range(n):
  m[a[i]] += 1
#print(m[:30])
mx = max(a)
ans = 0
for p in range(n):
  i = a[p]
  if m[i] != 1:
    continue
  divs = make_divisors(i)
  flg = True
  #print('i : ', i)
  #print(divs)
  for j in range(len(divs)):
    div = divs[j]
    if div == i:
      continue
    
    if m[div] > 0:
      flg = False
      break
  if flg:
    ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
MAX = 10 ** 6 + 10

one = a.count(1)
if one > 0:
  if one == 1:
    print(1)
  else:
    print(0)
  exit(0)

sieve = [True] * MAX
counts = [0] * MAX
a.sort()
ans = 0
sieve[0] = False
sieve[1] = False
for i in range(n):
  counts[a[i]] += 1
  if not sieve[a[i]]:
    continue
  for j in range(a[i]*2, MAX, a[i]):
    sieve[j] = False
  if counts[a[i]] == 1:
    ans += 1
  elif counts[a[i]] == 2:
    ans -= 1
    
print(ans)
### BUGGY CODE ###

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

a.sort()
i = 0
ans = 0

seen = []

while i < N:
    x = a[i]
    if x in seen:
        ans += 1
        i += 1
        continue
    else:
        seen.append(x)

    cnt = 1
    j = 1
    flag = True
    while j < x and i+j < N and flag:
        if a[i+j] != x:
            flag = False
        else:
            cnt += 1
        j += 1
            
    if not flag or cnt != x:
        ans += cnt
    i += cnt

print(ans)

### FIXED CODE ###


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

ans = 0
a_as = {}

for x in a:
    if x in a_as:
        a_as[x] += 1
    else:
        a_as[x] = 1

for x in a_as:
    if x > a_as[x]:
        ans += a_as[x]
    else:
        ans += abs(a_as[x]-x)
    
print(ans)
### BUGGY CODE ###

# 2019-11-13 08:30:54(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, m = [int(x) for x in sys.stdin.readline().split()]
    a = [int(x) for x in sys.stdin.readline().split()]
    a.sort()

    replace = []
    for _ in range(m):
        bi, ci = [int(x) for x in sys.stdin.readline().split()]
        replace += [ci] * bi
    
    replace.sort(reverse=True)

    for i in range(n):
        if i < len(replace):
            if a[i]< replace[i]:
                a[i] = replace[i]
                continue
            else:
                break
        else:
            break
    
    print(sum(a))



if __name__ == "__main__":
    main()


### FIXED CODE ###

# 2019-11-13 08:30:54(JST)
import sys
import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, m = [int(x) for x in sys.stdin.readline().split()]
    a = [int(x) for x in sys.stdin.readline().split()]

    a = list(collections.Counter(a).items())

    for _ in range(m):
        b, c = [int(x) for x in sys.stdin.readline().split()]
        a.append((c,b))
    
    a.sort(reverse=True)
    
    total = 0
    count = 0
    for i in range(n+m): # max
        select = a[i]
        for j in range(select[1], 0, -1):
            if count + j > n:
                continue
            else:
                count += j
                total += select[0] * j
                break
        if count == n:
            break
    
    print(total)

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

import sys
from itertools import accumulate

input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    for _ in range(min(41, K)):
        A_cumsum = [0] * N
        for i in range(N):
            a = i - A[i]
            b = i + A[i] + 1
            if a < 0:
                A_cumsum[0] += 1
            else:
                A_cumsum[a] += 1
            if N - 1 < b:
                pass
            else:
                A_cumsum[b] -= 1
        A = list(accumulate(A_cumsum))

    print(" ".join(map(str, A)))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8[:](i8,i8,i8[:])", cache=True)
def solve(N, K, A):
    for _ in range(min(41, K)):
        A_cumsum = np.zeros(shape=N, dtype=np.int64)
        for i in range(N):
            A_cumsum[max(0, i - A[i])] += 1
            b = i + A[i] + 1
            if N - 1 < b:
                pass
            else:
                A_cumsum[b] -= 1
        A = np.cumsum(A_cumsum)
    return A


def main():
    N, K = map(int, input().split())
    A = np.array(input().split(), dtype=np.int64)

    ans = solve(N, K, A)

    print(" ".join(map(str, ans)))


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

#N

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

S=[0]*(N+1)
for i in range(N):
    S[i+1]=S[i]+a[i]


#dp[i][j]は[i,j)の範囲で全てをマージする最小コスト
inf=10**15
dp=[[inf]*(N+1) for _ in range(N+1)]

#区間[i,j)を[i,k)+[k,j)に分けて考える
for d in range(1,N+1):#dはj-i
    for i in range(N+1):
        j=i+d
        if j>N:
            break
        if d==1:
            dp[i][j]=0
        else:
            for k in range(i,j):
                dp[i][j]=min(dp[i][j] , dp[i][k]+dp[k][j]+S[j]-S[i])
            
print(dp[0][-1])
            



### FIXED CODE ###

#N

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

S=[0]*(N+1)
for i in range(N):
    S[i+1]=S[i]+a[i]


#dp[i][j]は[i,j)の範囲で全てをマージする最小コスト
inf=10**15
dp=[[inf]*(N+1) for _ in range(N+1)]

#区間[i,j)を[i,k)+[k,j)に分けて考える
for d in range(1,N+1):#dはj-i
    for i in range(N+1):
        j=i+d
        if j>N:
            break
        if d==1:
            dp[i][j]=0
        else:
            for k in range(i,j):
                dp[i][j]=min(dp[i][j] , dp[i][k]+dp[k][j]+S[j]-S[i])
            
print(dp[0][-1])
### BUGGY CODE ###

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

ans = 1

for i in A:
  ans *= i
  
if ans > 10**18:
  ans = -1
  
print(ans)

### FIXED CODE ###

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

if 0 in A:
  ans = 0
  
else:
  ans = 1
  for i in range(N):
    ans *= A[i]
    if ans > 10**18:
      ans = -1
      break

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

N, K = map(int, input().split())
# A = sorted(list(map(int, input().split())),reverse=True)
A = list(map(int, input().split()))

uniq_items = []
for i in set(A):
    uniq_items.append(A.count(i))

uniq_items = sorted(uniq_items,reverse=True)

if len(uniq_items) <= K:
    print(0)
else:
    print(sum(uniq_items[K:]))


### FIXED CODE ###

from collections import Counter
N, K = map(int, input().split())
A = list(map(int, input().split()))

print(sum(sorted(Counter(A).values(),reverse=True)[K:]))
### BUGGY CODE ###

import sys
from collections import deque
n, m = map(int, input().split( ))
Edg = [[] for _ in range(n)]
#rev_Edg =  [[] for _ in range(n)]

Visited = [0]*n
Root_check = [1]*n
Dist = [0]*n
for i in range(m):
    v1,v2 = map(int, sys.stdin.readline().split( ))
    v1-=1
    v2-=1
    Edg[v1].append(v2)
    Root_check[v2] = 0
    
Roots = []
for i in range(n):
    if Root_check[i] == 1:
        Roots.append(i)
Q =deque()
for r in Roots:
    Q.append(r)
    while len(Q) > 0:
        v = Q.popleft()
        for w in Edg[v]:
            Dist[w] = max(Dist[w],Dist[v] +1)####
            Q.append(w)

print(max(Dist))


### FIXED CODE ###

import sys
from collections import deque
n, m = map(int, input().split( ))
Edg = [[] for _ in range(n)]
rev_Edg = [[] for _ in range(n)]
deg = [len(rev_Edg[i]) for i in range(n)]


Root_check = [1]*n
Dist = [0]*n
for i in range(m):
    v1,v2 = map(int, sys.stdin.readline().split( ))
    v1-=1
    v2-=1
    Edg[v1].append(v2)
    rev_Edg[v2].append(v1)
    deg[v2] += 1
    Root_check[v2] = 0
    

Q =deque()
for i in range(n):
    if Root_check[i] == 1:
        Q.append(i)

while len(Q) > 0:
    v = Q.popleft()
    for w in Edg[v]:
        Dist[w] = max(Dist[w],Dist[v] +1)####
        deg[w] -=1 ############
        if deg[w] == 0:##########
            Q.append(w)###########
            


print(max(Dist))
### BUGGY CODE ###

import numpy as np

def factorial(i):
    ans = 1
    for j in range(1,i+1):
        ans *= j
    return ans
N = int(input())
A = [input() for i in range(N)]
a = []
for i in A:
    b = list(i)
    b.sort()
    a.append(b)

a.sort()
c = list(map(list, set(map(tuple, a))))
d=[]
for i in c:
    if a.count(i)==1:
        continue
    d.append(a.count(i))
count=0
for i in d:

    if i>2:
        count += factorial(i) // (factorial(i - 2) * factorial(2))
    elif i ==2:
        count += 1
print(count)

### FIXED CODE ###

N = int(input())
A=[]
S={}
for i in range(N):
    a = list(input())
    a.sort()
    b = ''.join(a)
    if b not in S:
        S[b] = 1
    else:
        S[b] += 1


count=0
for i in S.values():
    if i==1:
        continue
    count += i*(i-1)//2
print(count)
### BUGGY CODE ###

def main():
    N = int(input())
    A = []
    for n in range(N):
        A.append(int(input()))

    max_A = max(A)
    argmax_A = [i for i, x in enumerate(A) if x == max(A)]
    if len(argmax_A) == 1:
        for n in range(N):
            if n in argmax_A:
                tmp = A.pop(n)
                print(max(A))
                A.insert(n, tmp)
            else:
                print(max_A)
    else:
        for n in range(N):
            print(max_A)
        
if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N = int(input())
    A = []
    for n in range(N):
        A.append(int(input()))

    A_cp = sorted(A)
    max1_A = A_cp.pop(-1)
    max2_A = max(A_cp)
    for a in A:
        if a == max1_A:
            print(max2_A)
        else:
            print(max1_A)
            
        
if __name__ == '__main__':
    main()