CodeEff/ECCO huggingface dataset:
# Original solution
def returnmax(numbers, i, N):
    nowmax = 0
    for j in range(N):
        if j != i:
            if nowmax < numbers[j]:
                nowmax = numbers[j]
    return nowmax
    
numbers = []
N = int(eval(input()))
for i in range(N):
    numbers.append(int(eval(input())))
for i in range(N):
    print((returnmax(numbers, i, N)))


# Optimized solution
def returnsecond(numbers, N):
    first = 0
    firc = 0;
    second = 0
    for j in range(N):
        if first < numbers[j]:
            first = numbers[j]
            firc = j
    for j in range(N):
        if(j != firc and second <= numbers[j]):
            second = numbers[j]

    return first, second;


numbers = []
N = int(eval(input()))

for i in range(N):
    numbers.append(int(eval(input())))
first, second = returnsecond(numbers, N)

for i in range(N):
    if numbers[i] != first:
        print(first)
    else:
        print(second)
# Original solution
#C - Exception Handling
N = int(eval(input()))
A = list(int(eval(input())) for _ in range(N))
A_sorted = list(set(sorted(A, reverse = False)))

ans = []
for i in A:
    A_copy = A.copy()
    A_copy.remove(i)
    ans.append(max(A_copy))

for i in ans:
    print(i)

# Optimized solution
# C - Exception Handling
N = int(eval(input()))
A = list(int(eval(input())) for _ in range(N))
A_sorted = list((sorted(A, reverse = True)))
A_sorted = A_sorted[0:2]

ans = []
for i in A:
    if i == A_sorted[0]:
        ans.append(A_sorted[1])
    else:
        ans.append(A_sorted[0])

for j in ans:
    print(j)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

L = [0] * (200000+1)
R = [0] * (200000+1)

L[0] = 0
for i in range(1, N+1):
    L[i] = max(A[i-1], L[i-1])

R[N] = 0
for i in range(N-1, 0, -1):
    R[i] = max(R[i+1], A[i])

#print(L)
#print(R)

for i in range(N):
    ans = max(L[i], R[i+1])
    print(ans)

# Optimized solution

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

N = int(eval(input()))
A = []
for i in range(N):
    a = int(eval(input()))
    A.append(a)

B = list(reversed(sorted(A)))

for i in range(N):
    # 最大か二番目を出せばいい
    if A[i] == B[0]:
        print((B[1]))
    else:
        print((B[0]))
# Original solution
from collections import deque
n = int(eval(input()))
d = deque([int(eval(input())) for i in range(n)])

for _ in range(n):
    x = d.popleft()
    print((max(d)))
    d.append(x)

# Optimized solution
n = int(eval(input()))
t = [int(eval(input())) for i in range(n)]
tt = sorted(t)
m = tt[-1]
mm = tt[-2]

for i in range(n):
    if t[i] == m:
        print(mm)
    else:
        print(m)
# Original solution
N = int(eval(input()))
max_1 = 0
max_2 = 0
nums = []
for _ in range(N):
    n = int(eval(input()))
    if n >= max_1:
        max_2 = max_1
        max_1 = n
    if n < max_1:
        if n >= max_2:
            max_2 = n
    nums.append(n)

for n in nums:
    if n == max_1:
        print(max_2)
    else:
        print(max_1)

# Optimized solution
N = int(eval(input()))
nums = [int(eval(input())) for _ in range(N)]
nums_copy = sorted(nums[:], reverse=True)
max_1 = nums_copy[0]
max_2 = nums_copy[1]

for n in nums:
    if n == max_1:
        print(max_2)
    else:
        print(max_1)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]

for i in range(n) :
  at = a[i]
  a[i] = 0
  print((max(a)))
  a[i] = at

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
a_max = max(a)
max_c = a.count(a_max)

for i in range(n) :
  if a[i] != a_max :
    print(a_max)
  else :
    if max_c == 1 :
      a[i] = 0
      print((max(a)))
    else :
      print(a_max)
# Original solution
n=int(eval(input()))
a = [eval(input()) for _ in range(n)]
c=[0]*n

for i in range(n):
	b=a.copy()
	b.remove(a[i])
	c[i]=sorted(b)[-1]
for i in range(n):
	print((c[i]))

# Optimized solution
n=int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b=sorted(a)
c=[0]*n

for i in range(n):
	if a[i]==b[-1]:
		c[i]=b[-2]
	else:
		c[i]=b[-1]
for i in range(n):
	print((c[i]))
# Original solution
N=int(eval(input()))
A=list(range(N))
S=list(range(N-1))

for i in range(N):
    A[i]=int(eval(input()))

for i in range(N):
    r=0
    for j in range(N):
     if j!=i:
       if A[j]>r:
          r=A[j]

    print(r)

# Optimized solution
N=int(eval(input()))
A=list(range(N))


r=0
count=0
for i in range(N):
    A[i]=int(eval(input()))
    if A[i]>r:
     r=A[i]
     count=i

for i in range(N):
    if i==count:
     del A[i]
     print((max(A)))
    else:
     print(r)
# Original solution
import copy
N = int(eval(input()))

lst = []
for i in range(N):
    lst.append(int(eval(input())))

for i in range(N):
    lstAns = copy.copy(lst)
    a = lstAns.pop(i)
    print((max(lstAns)))


# Optimized solution
N = int(eval(input()))

lst = []
for i in range(N):
    lst.append(int(eval(input())))

lstA = sorted(lst,reverse=True)

for i in range(N):
    if lst[i] == lstA[0]:
        print((lstA[1]))
    else:
        print((lstA[0]))
# Original solution
N = int(eval(input()))
A_List =[]
for i in range(N):
    A = int(eval(input()))
    A_List.append(A)
for i in range(N):
    print((max(A_List[:i]+A_List[i+1:])))

# Optimized solution
N = int(eval(input()))
A_List =[]
for i in range(N):
    A = int(eval(input()))
    A_List.append(A)
A_List2 = A_List.copy()
A_List2 = sorted(A_List2)

A_max = A_List2[-1]
A_max2 = A_List2[-2]

for a in A_List:
    if a ==A_max:
        print(A_max2)
    else:
        print(A_max)
# Original solution
from copy import deepcopy

N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
for i in range(N):
  a=deepcopy(A)
  del a[i]
  print((max(a)))


# Optimized solution
N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
max_val1=sorted(A)[-1]
max_val2=sorted(A)[-2]
for x in A:
  print((max_val2 if x==max_val1 else max_val1))
# Original solution
from collections import deque
n = int(eval(input()))
d = deque()
for _ in range(n):
  d.append(int(eval(input())))
for _ in range(n):
  b = d.popleft()
  print((max(d)))
  d.append(b)

# Optimized solution
n = int(eval(input()))
d = []
for _ in range(n):
  d.append(int(eval(input())))
a = sorted(d)
for i in range(n):
  if a[-1] == d[i]:
    print((a[-2]))
  else:
    print((a[-1]))
# Original solution
import copy

n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]

for i in range(n):
    tmp_list = copy.deepcopy(A)
    tmp_list.pop(i)
    print((max(tmp_list)))


# Optimized solution
import copy

n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]

A_sorted = sorted(A, reverse=True)

for i in range(n):
    if A[i] == A_sorted[0]:
        print((A_sorted[1]))
    else:
        print((A_sorted[0]))
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for x in range(n)]

import copy

for i in range(n):
   b = copy.deepcopy(a)
   b.pop(i)
   print((max(b)))


# Optimized solution
n = int(eval(input()))
A = [int(eval(input())) for x in range(n)]

right = [0]
left = [0]

for a in A:
   left.append(max(a, left[-1]))

for a in reversed(A):
   right.append(max(a, right[-1]))

for i in range(n):
   print((max(left[i], right[n-i-1])))
# Original solution
import copy
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = copy.deepcopy(a)
a.sort(reverse=True)
for v in b:
  if v==a[0]:
    print((a[1]))
  else:
    print((a[0]))

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = sorted(a)
for v in a:
  print((b[(v<b[-1])-2]))
# Original solution
import copy

N = int(eval(input()))

a_list = []
for i in range(N):
    a_list.append(int(eval(input())))

max_value = max(a_list)

for i in range(N):
  if a_list.count(max_value) > 1:
    print(max_value)
  else:
    if a_list[i] == max_value:
      print((sorted(a_list)[-2]))
    else:
      print(max_value)
  


# Optimized solution
N = int(eval(input()))

a_list = []
for i in range(N):
    a_list.append(int(eval(input())))

max_value = max(a_list)

if a_list.count(max_value) > 1:
  for i in range(N):
    print(max_value)
else:
  for i in range(N):
    if a_list[i] == max_value:
      print((sorted(a_list)[-2]))
    else:
      print(max_value)
# Original solution
from collections import deque
n = int(eval(input()))
a = deque()
for _ in range(n):
    a.append(int(eval(input())))

for i in range(n):
    tmp = a.popleft()
    print((max(a)))
    a.append(tmp)

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
sort_a = sorted(a, reverse=True)
amax = sort_a[0]
asecond = sort_a[1]
for i in range(n):
    tmp = a[i]
    if tmp == amax:
        print(asecond)
    else:
        print(amax)
# Original solution
import copy

n=int(eval(input()))
info=[]
for i in range(n):
    info.append(int(eval(input())))
   
for i in range(n):
    info2=copy.deepcopy(info)
    del info2[i]
    print((max(info2)))

# Optimized solution
n=int(eval(input()))
info=[]
for i in range(n):
    info.append(int(eval(input())))

info2=sorted(info,reverse=True)
max1=info2[0]
max2=info2[1]

for i in range(n):
    if info[i]==max1:
        print(max2)
    else:
        print(max1)
# Original solution
from collections import deque

n = int(eval(input()))
alist = deque()
for i in range(n):
    alist.append(int(eval(input())))



anslist = deque()
for _ in range(n):
    ai = alist.popleft()
    anslist.append(max(alist))
    alist.append(ai)

for i in anslist:
    print(i)
    
    

# Optimized solution

n = int(eval(input()))
alist = []
for i in range(n):
    alist.append(int(eval(input())))

amax = max(alist)
anslist = [amax]*n
if alist.count(amax)>=2:
    for i in anslist:
        print(i)
    exit()

if alist.count(amax)==1:
    maxindex = alist.index(amax)
    del alist[maxindex]
    anslist[maxindex]= max(alist)
    for i in anslist:
        print(i)
    exit()
# Original solution
N=int(eval(input()))
A=[int(eval(input())) for _ in range(N)]
ll=sorted(A)
  
for n in A:
  if n==max(A):
    print((ll[-2]))
  else:
    print((max(A)))

# Optimized solution
N=int(eval(input()))
A=[int(eval(input())) for _ in range(N)]
ll=sorted(A)
a=max(A)
b=ll[-2]
  
for n in A:
  if n==a:
    print(b)
  else:
    print(a)
# Original solution
n = int(eval(input()))
nums = [int(eval(input())) for _ in range(n)]

for i in range(n):
  print((max(nums[0: i] + nums[i + 1:])))


# Optimized solution
n = int(eval(input()))
nums = [int(eval(input())) for _ in range(n)]
max_num = max(nums)
max_cnt = len([i for i in nums if i == max_num])

for i in range(n):
  if nums[i] < max_num or max_cnt > 1:
    print(max_num)
  else:
    print((max(set(nums) - set([nums[i]]))))
# Original solution
from collections import deque
n = int(eval(input()))
a = deque()
for i in range(n):
    tmp = int(eval(input()))
    a.append(tmp)
#print(a)
for i in range(n):
    tmp = a.popleft()
    print((max(a)))
    a.append(tmp)

# Optimized solution
n = int(eval(input()))
max_1 = 0
max_2 = 0
a_list = []
for i in range(n):
    a = int(eval(input()))
    a_list.append(a)
    if max_1 < a:
        max_2 = max_1
        max_1 = a
    elif max_2 < a:
        max_2 = a
#print(max_1,max_2)
for i in range(n):
    if a_list[i] == max_1:
        print(max_2)
    else:
        print(max_1)
# Original solution
n=int(eval(input()))
a=[]

for i in range(n):
    a.append(int(eval(input())))

Max=max(a)
for i in range(n):
    b=a[:]
    if(b[i]==Max):
        del b[i]
        print((max(b)))
    else:
        print(Max)

# Optimized solution
n = int(eval(input()))
a = []

for i in range(n):
    a.append(int(eval(input())))

Max = max(a)
if(a.count(Max)>1):
    for _ in range(n):
        print(Max)
else:
    for i in range(n):
        if(a[i]==Max):
            a[i]=0
            print((max(a)))
        else:
            print(Max)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
ahead = 0
back = max(a[1:])
result = [back]
for i in range(1,n-1):
    ahead = max(ahead,a[i-1])
    if back == a[i]:
        back = max(a[(i+1):])
    result.append(max(ahead,back))
ahead = max(ahead,a[n-2])
result.append(ahead)
for j in range(n):
    print((result[j]))

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
a2 = sorted(a)
ma = a2[-1]
se = a2[-2]
result = []
for i in range(n):
    if a[i] == ma:
        result.append(se)
    else:
        result.append(ma)
for j in range(n):
    print((result[j]))
# Original solution
n = int(eval(input()))
ai = {}
max1 = 0
max2 = 0
for i in range(1, n+1):
    tmp = int(eval(input()))
    ai.setdefault(i, tmp)
    if tmp > max1:
        max1 = tmp
    elif tmp > max2:
        max2 = tmp

for i in range(1, n+1):
    if ai[i] == max1:
        print(max2)
    else:
        print(max1)

# Optimized solution
n = int(eval(input()))
ai = {}
max1 = 0
max2 = 0
for i in range(1, n+1):
    tmp = int(eval(input()))
    ai.setdefault(i, tmp)
    if tmp > max1:
        max2 = max1
        max1 = tmp
    elif tmp > max2:
        max2 = tmp

for i in range(1, n+1):
    if ai[i] == max1:
        print(max2)
    else:
        print(max1)
# Original solution
import copy
n=int(eval(input()))
a=[0]*n
for i in range(0,n):
  a[i]=int(eval(input()))
temp=copy.copy(a)
for i in range(0,n):
  temp[i]=0
  print((max(temp)))
  temp=copy.copy(a)
        

# Optimized solution
n=int(eval(input()))
a=[0]*n
for i in range(0,n):
  a[i]=int(eval(input()))
temp=sorted(a,reverse=True)
for i in range(0,n):
  if a[i]==temp[0]:
    print((temp[1]))
  else:
    print((temp[0]))
# Original solution
import copy
n=int(eval(input()))
a = [list(map(int, input().split())) for _ in range(n)]
a=sum(a,[])
a_sort=copy.copy(a)
a_sort.sort()
a_last,a_last2=a_sort[-1],a_sort[-2]
if a_last==a_last2:
  for i in range(n):
    print(a_last)
else:
  for i in range(n):
    if a[i]!=a_last:
      print(a_last)
    else:
      print(a_last2)

# Optimized solution
n=int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
a_max=max(a)
a_max2=sorted(a)[-2]
if a_max!=a_max2:
  for i in range(n):
    if a[i]!=a_max:
      print(a_max)
    else:
      print(a_max2)
else:
  for i in range(n):
    print(a_max)
# Original solution
import copy
length = int(eval(input()))
suretsu=[int(eval(input())) for i in range(length)]
result = []
zantei_max = max(suretsu)
for i in range(length):
    if (zantei_max == suretsu[i]):
        copy_suretsu = copy.deepcopy(suretsu)
        del copy_suretsu[i]
        new_max = max(copy_suretsu)
        result.append(str(new_max))
    else:
        result.append(str(zantei_max))
print(('\n'.join(result)))

# Optimized solution
length = int(eval(input()))
suretsu=[int(eval(input())) for i in range(length)]
result = []
sorted_suretsu = sorted(suretsu,reverse=True)
zantei_max = sorted_suretsu[0]

for i in range(length):
    if (zantei_max == suretsu[i]):
        result.append(str(sorted_suretsu[1]))
    else:
        result.append(str(zantei_max))
print(('\n'.join(result)))
# Original solution
import copy

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

s_la = sorted(la, reverse=True)

for a in la:
	max_la = copy.copy(s_la)
	max_la.remove(a)
	print((max_la[0]))

# Optimized solution

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

s_la = sorted(la, reverse=True)

for a in la:
	if a == s_la[0]:
		print((s_la[1]))
	else:
		print((s_la[0]))
# Original solution
from collections import deque
n = int(eval(input()))
a = deque( int(eval(input())) for i in range(n))
for i in range(n):
    s = a.popleft()
    m = max(a)
    print(m)
    a.append(s)

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
m = max(a)
p = a.index(m)
a.remove(m)
s = max(a)
for i in range(n):
    if i != p:
        print(m)
    else:
        print(s)
# Original solution
import copy as cp
N = int(eval(input()))
numbers = [int(eval(input())) for i in range(N)]

max_num = max(numbers)

for i in range(len(numbers)):
    if numbers[i] == max_num:
        temp_numbers = cp.copy(numbers)
        temp_numbers.pop(i)
        print((max(temp_numbers)))
    else :
        print(max_num)

# Optimized solution
N = int(eval(input()))
numbers = [int(eval(input())) for i in range(N)]

# 最大値を取得
max_num = max(numbers)

# 最大値を同じ値がいくつ在るかを確認
max_nums = numbers.count(max_num)

if max_nums >= 2:
    for i in range(len(numbers)):
        print(max_num)
else :
    max_index = numbers.index(max(numbers))
    for i in range(len(numbers)):
        if i == max_index:
            second_max = sorted(numbers)[-2]
            print(second_max)
        else :
            print(max_num)
# Original solution
import collections
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
set_A = list(set(A))
set_A.sort(reverse=True)
c = collections.Counter(A)
Max = max(A)
Max_list = [i for i, v in enumerate(A) if v == max(A)]
for i in range(N):
    if A[i] == Max:
            if len(Max_list) > 1:
                print((A[i]))
            else:
                print((set_A[1]))
    else:
        print(Max)


# Optimized solution
import copy
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
set_A = list(set(A))
set_A.sort(reverse=True)
A_copy = copy.deepcopy(A)
A_copy.sort(reverse=True)
Max = max(A)
cnt = 0
for i in range(N):
    if A[i] == Max:
        cnt += 1
for i in range(N):
    if A[i] == Max:
        if cnt > 1:
            print(Max)
        else:
            print((set_A[1]))
    else:
        print(Max)
# Original solution
N = int(eval(input()))
#A = [int(i) for i in input().split()]
A = [int(eval(input())) for _ in range(N)]

for i in range(N):
	tmp = A[i]
	A[i] = 0
	print((max(A)))
	A[i] = tmp

# Optimized solution
N = int(eval(input()))
#A = [int(i) for i in input().split()]
A = [int(eval(input())) for _ in range(N)]

idx1, ma1 = A.index(max(A)), max(A)

tmp = A[idx1]
A[idx1] = 0
idx2, ma2 = A.index(max(A)), max(A)

A[idx1] = tmp

for i in A:
	if i == ma1:
		print(ma2)
	else:
		print(ma1)
# Original solution
import copy

N = int(eval(input()))
a = [int(eval(input())) for i in range(N)]
for i in range(N):
  b = copy.deepcopy(a)
  del b[i]
  print((sorted(b, reverse=True)[0]))


# Optimized solution
from heapq import *

N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
h=[]
for i in A:
    heappush(h, -i)
maxh = -heappop(h)
secondh = -heappop(h)
for i in A:
    print((maxh if i != maxh else secondh))
# Original solution
import copy



N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]

for i in range(N):
   # B = copy.deepcopy(A)
    tmp = A[i]
    A[i] = 0
    ans = max(A)
    A[i] = tmp
    print(ans)
             


# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
B = [ [0] * 2 for i in range(N)]

for i in range(N):
    B[i][0] = A[i]
    B[i][1] = i

B.sort(reverse=True)
for i in range(N):
    if B[0][1] == i:
        print((B[1][0]))
    else:
        print((B[0][0]))
# Original solution
#C
import copy
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
for i in range(n):
    tmp = copy.copy(a)
    tmp.pop(i)
    tmp.sort()
    print((tmp[-1]))


# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
max_a = max(a)
max_idx = a.index(max_a)
for i in range(n):
    if i == max_idx:
        tmp = a
        tmp.sort(reverse=True)
        print((tmp[1]))
    else:
        print(max_a)
# Original solution
n = int(eval(input()))
data = [int(eval(input())) for k in range(n)]
m1,m2 = sorted(data, reverse=1)[:2]
b = [m2 if x==m1 else m1 for x in data]
print(('\n'.join(map(str,b))))

# Optimized solution
import sys
input = sys.stdin.readline

n = int(eval(input()))
data = [int(eval(input())) for k in range(n)]
m1,m2 = sorted(data, reverse=1)[:2]
b = [m2 if x==m1 else m1 for x in data]
print(('\n'.join(map(str,b))))
# Original solution
from collections import deque
n = int(eval(input()))
a = deque([int(eval(input())) for _ in range(n)])
for i in range(n):
    ak = a[i]
    del a[i]
    print((max(a)))
    a.appendleft(ak)


# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
max_a = max(a)
set_a = set(a)
max_n = a.count(max_a)
if len(set_a) == 1:
    s_set_a = max_a
else:
    if max_n > 1:
        s_set_a = max_a
    else:
        s_set_a = sorted(set_a)[-2]

for i in range(n):
    if max_a == a[i]:
        print(s_set_a)
    else:
        print(max_a)
# Original solution
n = int(eval(input()))
li = []
for i in range(n):
    li.append(int(eval(input())))
m = max(li)
li2 = li.copy()
li2.remove(max(li2))
d = max(li2)
for i in range(n):
    if li[i] == max(li):
        print(d)
    else:
        print(m)

# Optimized solution
n = int(eval(input()))
li = []
for i in range(n):
    x = int(eval(input()))
    li.append(x)
p = max(li)
r = li.index(p)
li.remove(p)
q = max(li)
for i in range(n):
    if i == r:
        print(q)
    else:
        print(p)
# Original solution
import copy

N=int(eval(input()))
L=[]
tmp=[]
for _ in range(N):
  L.append(int(eval(input())))

T=sorted(copy.deepcopy(L))
h=max(L)
h2=T[len(T)-2]

for i in range(N):
  if L[i]!=h:
    print(h)
  elif L[i]!=h2:
    print(h2)
  else:
    tmp=copy.deepcopy(L)
    del tmp[i]
    print((max(tmp)))

# Optimized solution
N=int(eval(input()))
L=[]
for _ in range(N):
  L.append(int(eval(input())))
sL=sorted(L)
sL.reverse()
m=max(L)
m2=sL[1]

for i in range(N):
  if L[i]==m:
    print(m2)
  else:
    print(m)
# Original solution
def slove():
    import sys
    import copy
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [int(input().rstrip('\n')) for _ in range(n)]
    b = copy.deepcopy(a)
    b.sort(reverse=True)
    for v in a:
        if v == b[0]:
            print((b[1]))
        else:
            print((b[0]))


if __name__ == '__main__':
    slove()


# Optimized solution
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [int(input().rstrip('\n')) for _ in range(n)]
    b = sorted(a, reverse=True)
    for i in range(len(a)):
        if a[i] == b[0]:
            print((b[1]))
        else:
            print((b[0]))


if __name__ == '__main__':
    slove()
# Original solution
def p_c():
    N = int(eval(input()))
    A = [int(eval(input())) for _ in range(N)]

    for i in range(N):
        a = A.copy()
        a.pop(i)
        print((max(a)))


if __name__ == '__main__':
    p_c()

# Optimized solution
def p_c():
    N = int(eval(input()))
    A = [int(eval(input())) for _ in range(N)]

    m = max(A)
    a = A.index(m)
    A.pop(a)
    b = max(A)

    for i in range(N):
        if i == a:
            print(b)
        else:
            print(m)


if __name__ == '__main__':
    p_c()
# Original solution
import copy
s=int(eval(input()))
list1=[eval(input()) for _ in range(s)]
for i in range(len(list1)):
  list2=copy.copy(list1)
  list2.remove(list2[i])
  list2=sorted(list2,key=lambda x:-int(x))
  print((list2[0]))


# Optimized solution
import copy
s=int(eval(input()))
list1=[eval(input()) for _ in range(s)]
list2=copy.copy(list1)
list2=sorted(list2,key=lambda x:-int(x))
for i in list1:
    if list2[0]==i:
      print((list2[1]))
    else:
      print((list2[0]))
# Original solution
import sys
import heapq
import copy

n = int(eval(input()))
a = []

for _ in range(n):
	a.append(-1 * int(eval(input())))

b = copy.deepcopy(a)
heapq.heapify(b)

for i in range(n):
	maximum = heapq.heappop(b)
	if maximum == a[i]:
		tmp = maximum
		maximum = heapq.heappop(b)
		print((maximum * (-1)))
		heapq.heappush(b,tmp)
	else:
		print((maximum * (-1)))
	heapq.heappush(b,maximum)


# Optimized solution
import bisect

n = int(eval(input()))

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

a2 = sorted(a)

max_a = a2[-1]
index = bisect.bisect_left(a2,max_a)
num = n-index

if num > 1:
  for _ in range(n):
    print((a2[-1]))
else:
  for i in range(n):
    if a[i] == a2[-1]:
      print((a2[-2]))
    else:
      print((a2[-1]))
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
ma = max(a)

for i in range(n):
  if a[i] != ma:
    print(ma)
  elif a.count(ma) > 1:
    print(ma)
  else:
    temp = a[:]
    del temp[i]
    print((max(temp)))

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
ma = max(a)
sma = sorted(a)[-2]

for i in range(n):
  if a[i] != ma:
    print(ma)
  else:
    print(sma)