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

from operator import itemgetter

n = int(input())
sn = []

for i in range(n):
    s = input()
    flg = 0
    for j in range(len(sn)):
        if(sn[j][0] == s):
            sn[j][1] += 1
            flg += 1
    if(flg == 0):
        sn.append([s,1])
        
sn.sort(key=itemgetter(1))
sn.reverse()
#print(sn)

cnt = sn[0][1]
for i in sn:
    if(int(i[1]) == cnt):
        print(i[0])
        continue
    else:
        break



### FIXED CODE ###

from operator import itemgetter
import datetime

n = int(input())
sn = dict()

for i in range(n):
    s = input()
    if(s in sn):
        sn[s] += 1
    else:
        sn[s] = 1

sn = sorted(sn.items(), key=lambda x:(-x[1],x[0]))
#print(sn)

max_val = max(dict(sn).values())

for si in sn:
    if(int(si[1]) == max_val):
        print(si[0])
    else:
        break
### BUGGY CODE ###

while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		A.append(int(input()))
	end=len(A)
	MAX=[0]*end
	for i in range(end):
		for j in range(i+1,end+1):
			s=sum(A[i:j])
			if MAX[i]<s:
				MAX[i]=s
	print(max(MAX))

### FIXED CODE ###

while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		x=int(input())
		A.append(x)

	B=[int()]*n
	B[0]=A[0]
	for i in range(1,n):
		if A[i]>=A[i]+B[i-1]:
			B[i]=A[i]
		else:
			B[i]=A[i]+B[i-1]
	print(max(B))
### BUGGY CODE ###

N,M=map(int,input().split())
a_list=[int(x) for x in input().split()]

import numpy as np
A=np.array(a_list)
counts=[0]*N
for i in range(M):
    max_id=np.argmax(A)
    A[max_id] /=2
    counts[max_id]+=1

    money=0
for x,y in zip(a_list,counts):
    money+=int(x/2**y)
print(money)

### FIXED CODE ###

import numpy as np
import heapq
N,M=map(int,input().split())
a_list=[int(x) for x in input().split()]

A=list([-1*x for x in a_list])
heapq.heapify(A)

for m in range(M):
    max_a=heapq.heappop(A)
    half=max_a/2
    heapq.heappush(A,half)

result=sum([-1*int(x) for x in A])
print(result)
### BUGGY CODE ###

n_s = input()
n_s = n_s[::-1]
#n = int(n_s)

pay = 0
back = 0
flag = 0

dp = [[0,0] for _ in range(len(n_s) + 1)]

dp[0][0] = int(n_s[0])
dp[0][1] = 10 - int(n_s[0])

for i in range(len(n_s)):
  i += 1
  if i == len(n_s):
    n = 0
  else:
    n = int(n_s[i])
  
  dp[i][0] = min(dp[i-1][0] + n, dp[i-1][1] + n+1)
  dp[i][1] = min(dp[i-1][0] + (10-n), dp[i-1][1] + (10-n-1))

print(min(dp[-1]))

### FIXED CODE ###

n_s = input()
n_s = n_s[::-1]
#n = int(n_s)

pay = 0
back = 0
flag = 0

dp = [[0,0] for _ in range(len(n_s) + 1)]

dp[0][0] = int(n_s[0])
dp[0][1] = 10 - int(n_s[0])

for i in range(len(n_s)):
  i += 1
  if i == len(n_s):
    n = 0
  else:
    n = int(n_s[i])
  
  dp[i][0] = min(dp[i-1][0] + n, dp[i-1][1] + n+1)
  dp[i][1] = min(dp[i-1][0] + (10-n), dp[i-1][1] + (10-n-1))

print(min(dp[-1]))
### BUGGY CODE ###

# coding: utf-8
import re
import bisect
from datetime import datetime as dt


def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    # データの状態に左右されないためにrandom.choice()を用いることもある。
    # ref = random.choice(arr)
    ref = arr[0]
    ref_count = 0

    for ele in arr:
        if ele < ref:
            left.append(ele)
        elif ele > ref:
            right.append(ele)
        else:
            ref_count += 1
    left = quick_sort(left)
    right = quick_sort(right)
    return left + [ref] * ref_count + right


n, m = map(int, input().split())
A = list(map(int, input().split()))
for i in range(m):
    b, c = map(int, input().split())
    for i in range(b):
        A.append(c)
A = quick_sort(A)
print(sum(A[len(A)-n:len(A)]))


### FIXED CODE ###

n,m=map(int,input().split())
a = list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in [0]*m]
a.sort()
bc.sort(key=lambda x: x[1], reverse=True)  
i=0
for b,c in bc:
    for j in range(i,min(n,i+b)):
        if a[j] < c:
            a[j] = c
            i+=1
        else:
            break
print(sum(a))
### BUGGY CODE ###

#!/usr/bin/env python3
#ABC139 E

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = [deque() for _ in range(n)]
for i in range(1,n+1):
    x = LI()
    for j in x:
        a[i-1].append((i,j))
ans = 0
for j in range(n**2+1):
    check = [1]*n
    flg = False
    flg2 = False
    for i in range(n):
        if len(a[i]) == 0 or check[i] == 0:
            continue
        (x,y) = a[i].popleft()
        flg2 = True
        check[i] = 0
        if a[y-1][0] == (y,x) and check[y-1]:
            a[y-1].popleft()
            flg = True
            check[y-1] = 0
        else:
            a[i].appendleft((x,y))
    if flg:
        ans += 1
    if not flg2:
        print(ans)
        quit()
for i in a:
    if len(i) != 0:
        print(-1)
        quit()
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
#ABC139 E

import sys
import math
import bisect
import time
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = [deque() for _ in range(n)]
for i in range(1,n+1):
    x = LI()
    for j in x:
        a[i-1].append((i,j))
ans = 0
s = time.time()
for j in range(n*(n-1)//2+1):
    check = [1]*n
    flg = False
    flg2 = False
    if time.time() - s > 1.6:
        print(n*(n-1)//2)
        quit()
    for i in range(n):
        if len(a[i]) == 0 or check[i] == 0:
            continue
        (x,y) = a[i].popleft()
        flg2 = True
        check[i] = 0
        if a[y-1][0] == (y,x) and check[y-1]:
            a[y-1].popleft()
            flg = True
            check[y-1] = 0
        else:
            a[i].appendleft((x,y))
    if flg:
        ans += 1
    if not flg:
        for i in a:
            if len(i) != 0:
                print(-1)
                quit()
    if not flg2:
        print(ans)
        quit()
### BUGGY CODE ###

import fractions
from functools import reduce
K = int(input())

def gcd(*nums):
    return reduce(fractions.gcd, nums)

s = 0
for a in range(1,K+1):
    for b in range(1,a+1):
        for c in range(1,b+1):
            if a == b and b == c:
                s += gcd(a,b,c)
            elif a == b or a == c or b == c:
                s += gcd(a,b,c) * 3
            else:
                s += gcd(a,b,c) * 6
print(s)


### FIXED CODE ###

import math
from functools import reduce
K = int(input())

def gcd(*nums):
    return reduce(math.gcd, nums)

s = 0
for a in range(1,K+1):
    for b in range(1,a+1):
        for c in range(1,b+1):
            if a == b and b == c:
                s += gcd(a,b,c)
            elif a == b or a == c or b == c:
                s += gcd(a,b,c) * 3
            else:
                s += gcd(a,b,c) * 6
print(s)
### BUGGY CODE ###

h, w, m = map(int, input().split())
a_list = []
b_list = []
h_list = [0 for _ in range(h)]
w_list = [0 for _ in range(w)]
for i in range(m):
    a, b = map(int, input().split())
    a_list.append([a,b])
    h_list[a - 1] += 1
    w_list[b - 1] += 1
w_flag = [0 for _ in range(w)]
for i in range(w):
    if w_list[i] == max(w_list):
        w_flag[i] = 1
h_flag = [0 for _ in range(h)]
for i in range(h):
    if h_list[i] == max(h_list):
        h_flag[i] = 1
flag = 0   
for i in range(m):
    if h_flag[a_list[i][0] - 1] == 1 and w_flag[a_list[i][1] - 1] == 1:
        flag += 1
s = sum(h_flag) * sum(w_flag)
print(max(h_list) + max(w_list) - 1 if flag == s else max(h_list) + max(w_list))        


### FIXED CODE ###

h, w, m = map(int, input().split())
a_list = []
b_list = []
h_list = [0 for _ in range(h)]
w_list = [0 for _ in range(w)]
for i in range(m):
    a, b = map(int, input().split())
    a_list.append([a,b])
    h_list[a - 1] += 1
    w_list[b - 1] += 1
h_max = max(h_list)
w_max = max(w_list)
w_flag = [0 for _ in range(w)]
for i in range(w):
    if w_list[i] == w_max:
        w_flag[i] = 1
h_flag = [0 for _ in range(h)]
for i in range(h):
    if h_list[i] == h_max:
        h_flag[i] = 1
flag = 0   
for i in range(m):
    if h_flag[a_list[i][0] - 1] == 1 and w_flag[a_list[i][1] - 1] == 1:
        flag += 1
s = sum(h_flag) * sum(w_flag)
print(h_max + w_max - 1 if flag == s else h_max + w_max)
### BUGGY CODE ###

import heapq

N = int(input())
nb = [[] for _ in range(N)]
for i in range(N - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    nb[a].append((c, b))
    nb[b].append((c, a))
for x in nb:
    x.sort()

Q, K = map(int, input().split())
K -= 1

dist = [10 ** 10] * N
visited = set()
h = [(0, K, -1)]
while h:
    d0, node, parent = heapq.heappop(h)
    if node in visited:
        continue
    visited.add(node)
    dist[node] = d0
    for d1, child in nb[node]:
        if child != parent:
            heapq.heappush(h, (d0 + d1, child, node))

for i in range(Q):
    x, y = map(int, input().split())
    # print(f"{x}->K = {dist[x]}, K->{y} = {dist[y]}")
    print(dist[x - 1] + dist[y - 1])


### FIXED CODE ###

import sys
import heapq

input = sys.stdin.readline


def main():

    N = int(input())
    nb = [[] for _ in range(N)]
    for i in range(N - 1):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        nb[a].append((c, b))
        nb[b].append((c, a))
    for x in nb:
        x.sort()

    Q, K = map(int, input().split())
    K -= 1

    dist = [2 ** 62] * N
    h = [(0, K, -1)]
    while h:
        d0, node, parent = heapq.heappop(h)
        if d0 >= dist[node]:
            continue
        dist[node] = d0
        for d1, child in nb[node]:
            if child != parent and d0 + d1 < dist[child]:
                heapq.heappush(h, (d0 + d1, child, node))

    for i in range(Q):
        x, y = map(int, input().split())
        # print(f"{x}->K = {dist[x]}, K->{y} = {dist[y]}")
        print(dist[x - 1] + dist[y - 1])


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

n = int(input())
s = []
for i in range(n):
	s.append(sorted(input()))
	

ans = 0
for i in range(n-1):
	for j in range(i+1, n):
		if s[i] == s[j]:
			ans += 1

print(ans)

### FIXED CODE ###

n = int(input())
st = {}
sv = {}
for i in range(n):
	tmp = "".join(sorted(input()))
	if tmp in st.keys():
		sv[tmp] += st[tmp]
		st[tmp] += 1
	else:
		st[tmp] = 1
		sv[tmp] = 0


print(sum(sv.values()))
### BUGGY CODE ###

import sys

H, N = map(int, input().split())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

magics = {}
for a, b in AB:
    for i in range(H // a + 2):
        if min(i * a, H) not in magics:
            magics[min(i * a, H)] = i * b
        else:
            magics[min(i * a, H)] = min(magics[min(i * a, H)], i * b)

sorted_keys = sorted(magics.keys())
dp = [float('inf') for _ in range(H+1)]

for key in sorted_keys:
    dp[key] = min(dp[key], magics[key])

for h in range(H):
    for key in sorted_keys:
        dp[min(h + key, H)] = min(dp[min(h + key, H)], dp[h] + magics[key])

print(dp[-1])


### FIXED CODE ###

import sys

H, N = map(int, input().split())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

dp = [0 for _ in range(H + max(AB, key=lambda x: x[0])[0])]
for h in range(1, len(dp)):
    dp[h] = min(dp[h-a] + b for a, b in AB)

print(dp[H])
### BUGGY CODE ###

# import numpy as np
# import queue
# import heapq


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def r(a, b):
    return (a ** 4) + ((a ** 3) * b) + ((a ** 2) * (b ** 2)) + (a * (b ** 3)) + (b ** 4)


def main():
    print(*solve())


def solve():
    X = int(input())
    facts = factorization(X)

    facts.sort(key=lambda x: x[0])
    f0 = facts[0][0]

    f1 = X // f0

    for a in range(10**7):
        b = a - f0
        if r(a, b) == f1:
            return a, b


if __name__ == "__main__":
    main()


### FIXED CODE ###

"""
A^5 - B^5
= (A - B)(A^4 + A^3*B + A^2*B^2 + A*B^3 + B^4)
= (A - B){(A + B) * (A^3 + B^3) + A^2*B^2}
= (A - B){(A + B)^2 * (A^2 - AB + B^2) + A^2*B^2}

-> (A + B)^2 > 1, (A^2 - AB + B^2) > 1, A^2*B^2 > 1.
"""


def main():
    print(*solve())


def solve():
    X = int(input())

    for a in range(-1000, 1000):
        for b in range(-1000, 1000):
            if a ** 5 - b ** 5 == X:
                return a, b


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

import sys
import heapq
from collections import Counter
from math import sqrt

n = int(input())
a_s = [int(i) for i in sys.stdin.readline().split()]
a_s.sort()
_max = max(a_s)
ct = Counter(a_s)
cnt = 0
ls = [0] * (10**6+1)
for a in a_s:
    if ls[a] == 1:
        cnt += 1
        continue
    elif ct[a] > 1:
        cnt += 1
    for i in range(a, _max+1):
        if ls[i] == 1:
            continue
        if i % a == 0:
            ls[i] = 1

print(n - cnt)

### FIXED CODE ###

import sys
import heapq
from collections import Counter
from math import sqrt

n = int(input())
a_s = [int(i) for i in sys.stdin.readline().split()]
a_s.sort()
_max = max(a_s)
ct = Counter(a_s)
cnt = 0
ls = [False] * (10**6+1)
for a in a_s:
    if ls[a]:
        cnt += 1
        continue
    elif ct[a] > 1:
        cnt += 1
    for i in range(a, _max+1, a):
        if ls[i]:
            continue
        if i % a == 0:
            ls[i] = True

print(n - cnt)
### BUGGY CODE ###

import numpy as np

n,k,q=map(int, input().split())
p = np.full(n,k)

for i in range(q):
    a=int(input())
    p[a-1]+=1
    p-=1
    
for i in range(n):
    if(p[i]>0):
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

import numpy as np
import sys

n,k,q=map(int, input().split())
p = np.full(n,k-q)

for i in range(q):
    a=int(sys.stdin.readline())
    p[a-1]+=1
    
for i in range(n):
    if(p[i]>0):
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

from fractions import *
import sys
N, M = map(int, input().split())

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

a = sorted(a)
bc = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]

bc = sorted(bc)    

subar = a
for i in bc:
    sc = [i[1]] * i[0]
    suba = []
    ra = subar[i[0]:]
    if i[0] == len(a):
        suba = a
    suba = subar[:i[0]]
    if i[1] - max(suba) < 0:
        continue
    subar = sc + ra
    subar.sort()

print(sum(subar))





### FIXED CODE ###

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

a.sort()

pairs = [list(map(int, input().split())) for _ in range(m)]
pairs = sorted(pairs, key=lambda x: x[1])
cnt = 0
ans = 0
while cnt < n:
    if pairs != [] and a[-1] < pairs[-1][1] and cnt+pairs[-1][0] <= n:
        cnt += pairs[-1][0]
        ans += pairs[-1][0]*pairs[-1][1]
        pairs.pop(-1)
    elif pairs != [] and a[-1] < pairs[-1][1] and cnt+pairs[-1][0] > n:
        ans += (n - cnt)*pairs[-1][1]
        cnt += n - cnt
        break
    else:
        cnt+= 1
        ans += a[-1]
        a.pop(-1)

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

# UnionTreeクラス：グループ分けを木構造で管理する
class UnionFind():
    def __init__(self, N):
        self.par = [i for i in range(N)]
        self.N = N

    # xのrootを返す
    def root(self, x):
        return x if self.par[x] == x else self.root(self.par[x])

    # x, yが同じrootの場合true
    def same(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        return rx == ry

    # x,yのrootが違った場合、併合
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if(rx != ry):
            self.par = [ry if i == rx else i for i in self.par]

def output(uf):
    count = 0
    for i in range(uf.N):
        sub_par = uf.par[i+1:]
        count += len(sub_par) - sub_par.count(uf.par[i])

    return count



n, m = (int(i) for i in input().split())
input_arr = [[int(i) for i in input().split()] for i in range(m)] 

uf = UnionFind(n)
#input_arr = [[1,2],[3,4],[1,3],[2,3],[1,4]]

#print(output(uf))
result = [output(uf)]
for i in input_arr[::-1]:
    a = i[0]-1
    b = i[1]-1
    uf.unite(a,b)
    result.append(output(uf))
    #print(output(uf))
    #print("{},{}:{}:{}".format(a, b, uf.par, output(uf) ))

for i in result[::-1][1:]:
    print(i)

#print(uf.par)


### FIXED CODE ###

# UnionTreeクラス：グループ分けを木構造で管理する
class UnionFind():
    def __init__(self, N):
        self.par = [i for i in range(N)]
        self.size = [1] * N
        self.N = N

    # xのrootを返す
    def root(self, x):
        if self.par[x] == x:
            return x
        else: 
            self.par[x] = self.root(self.par[x])
            return self.root(self.par[x])

    # x, yが同じrootの場合true
    def same(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        return rx == ry

    # x,yのrootが違った場合、併合
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if self.size[rx] < self.size[ry]:
            self.par[rx] = ry
            self.size[ry] += self.size[rx]
        else:
            self.par[ry] = rx
            self.size[rx] += self.size[ry]

n, m = (int(i) for i in input().split())
input_arr = [[int(i) for i in input().split()] for i in range(m)] 

uf = UnionFind(n)
#input_arr = [[1,2],[3,4],[1,3],[2,3],[1,4]]

#print(output(uf))
result = [int(n*(n-1)/2)]
for i in input_arr[::-1]:
    a = i[0]-1
    b = i[1]-1
    if not uf.same(a,b):
        x = uf.size[uf.root(a)] * uf.size[uf.root(b)]
        uf.unite(a,b)
        result.append(int(result[-1]-x))
    else:
        result.append(result[-1])

for i in result[::-1][1:]:
    print(i)

#print(uf.par)
### BUGGY CODE ###

import math
k = int(input())
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for n in range(1,k+1):
            ans += math.gcd(i,math.gcd(j,n))
print(ans)


### FIXED CODE ###

import math
k = int(input())
ans = 0
if k < 3:
    for i in range(1,k+1):
        for j in range(1,k+1):
            for n in range(1,k+1):
                ans += math.gcd(i,math.gcd(j,n))
else: 
    #i*j
    for n in range(1,k+1):
        for i in range(1,k+1):
            ans += math.gcd(n,i)
            for j in range(i+1,k+1):            
                ans += 2*(math.gcd(math.gcd(i,j),n))

    '''
        for i in range(1,k+1):
            for j in range(i+1,k+1):
                for k in range(j+1,k+1):
                    ans += math.gcd(i,math.gcd(j,k))
    '''
print(ans)
### BUGGY CODE ###

c = int(input())
n_list = list(map(int, input().split()))

i = 1

for n in n_list:
    i = i * n

if i > (10 ** 18):
    print(-1)
else:
    print(i)


### FIXED CODE ###

c = int(input())
n_list = list(map(int, input().split()))

if min(n_list) == 0:
    print(0)
else:
    i = 1
    ERR = 10 ** 18
    flag = False
    for n in n_list:
        i = i * n
        if i > ERR:
            flag = True
            break

    if flag:
        print(-1)
    else:
        print(i)
### BUGGY CODE ###

N = int(input())
a = list(map(int, input().split()))
li = []
for i in range(N):
    li.append(a.count(i + 1))
    print(li[i])


### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
li = [0] * N

for i in range(N-1):
    li[a[i]-1] = li[a[i]-1] + 1

for i in range(N):
    print(li[i])
### BUGGY CODE ###

N = int(input())
As = list(sorted(list(map(int, input().split()))))

result = 0
stored = []
while len(As)!=0:
    item = As.pop()
    is_exist = False
    if item in stored:
        continue
    for A in As:
        if item%A==0:
            is_exist = True
            break
    if not is_exist:
        result+=1
    stored.append(item)
print(result)


### FIXED CODE ###

N = int(input())
As = list(sorted(list(map(int, input().split()))))

max_num = max(As)
tfs = [0 for _ in range(max_num+1)]

for A in As:
    if tfs[A] != 0:
        tfs[A] = 2
        continue
    for j in range(A, max_num+1, A):
        tfs[j]+=1

result = 0
for A in As:
    if tfs[A] == 1:
        result+=1
print(result)
### BUGGY CODE ###

import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
n,m=map(int,input().split())

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

for i in range(m):
	A[A.index(max(A))]//=2
	
print(sum(A))

### FIXED CODE ###

import heapq
n,m=map(int,input().split())
a=list(map(int,input().split()))
a = list(map(lambda x: x*(-1), a))  # 各要素を-1倍

heapq.heapify(a)

for i in range(m):
    minimum=heapq.heappop(a)
    mini=((minimum*(-1))//2)*(-1)
    heapq.heappush(a,mini)
    
print(-sum(a))
### BUGGY CODE ###

import numpy as np
N = int(input())
A=np.array([])
for i in range(N):
    A=np.append(A, int(input()) )
max_index=np.argmax(A)
a_max=int(A[max_index])
a_second=int(np.amax(np.delete(A,max_index)))
for i in range(max_index):
        print(a_max)
print(a_second)
for i in range(max_index+1,N):
        print(a_max)

### FIXED CODE ###

import numpy as np
N = int(input())
A = np.array([int(input()) for i in range(N)])

max_index=np.argmax(A)
a_max=int(A[max_index])
a_second=int(np.amax(np.delete(A,max_index)))
A[:]=a_max
A[max_index]=a_second
for a in A:
    print(int(a))
### BUGGY CODE ###

def solve():
    n=int(input())
    a=[int(input()) for _ in range(n)]
    num1=max(a)
    count=0
    while count!=n:
        if a[count]==num1:
            if count==0:
                print(max(a[1:]))
            elif count==n-1:
                print(max(a[:n-1]))
            else:
                print(max(max(a[:count]),max(a[count+1:])))
        else:
            print(num1)
        count+=1
solve()


### FIXED CODE ###

def solve():
    n=int(input())
    num=[]
    def append(num1):
        num.append(num1)
    def count1(num2):
        return num.count(num2)
    for i in range(n):
        a=int(input())
        append(a)
    max1=max(num)
    count=count1(max1)
    if count>1:
        for i in range(n):
            print(max1)
    else:
        for i in range(n):
            if num[i]==max1:
                if i==0:
                    print(max(num[1:]))
                elif i==n-1:
                    print(max(num[:n-1]))
                else:
                    print(max(max(num[:i]),max(num[i+1:])))
            else:
                print(max1)
solve()