CodeEff/ECCO huggingface dataset:
# Original solution
import sys
input = sys.stdin.readline

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
ans=max(a)
for i in range(n):
    print((ans if a[i]!=ans else sorted(a)[-2]))

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

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
ans=max(a)
if a.count(ans)>1:
    for _ in range(n):
        print(ans)
else:
    for i in range(n):
        print((ans if a[i]!=ans else sorted(a)[-2]))
# Original solution

import copy

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

chinpo = max(A)
B = copy.copy(A)
B.remove(max(A))
chinchin = max(B)

for i in range(N):
    if i == A.index(max(A)):
        print(chinchin)
    else:
        print(chinpo)


# Optimized solution
import copy

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

chinpo = max(A)
B = copy.copy(A)
B.remove(max(A))
chinchin = max(B)

for i in range(A.index(max(A))):
    print(chinpo)
print(chinchin)
for i in range(A.index(max(A))+1,N):
    print(chinpo)
# Original solution
import copy

N = int(eval(input()))

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

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

# Optimized solution
import copy

N = int(eval(input()))

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

B = copy.copy(A)
B.sort()

for i in range(N):
    if A[i] == B[-1]:
        print((B[-2]))
    else:
        print((B[-1]))
# Original solution
import sys
N = int(eval(input()))

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


MAX = max(A)

if A.count(MAX) == N:
  for _ in range(N):
    print(MAX)

  
else:

  two = sorted(set(A))[-2]
  for i in range(N):
    if A[i] == MAX and A.count(MAX) == 1:
      print(two)
    else:
      print(MAX)

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

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


MAX = max(A)

if A.count(MAX) != 1:
  for _ in range(N):
    print(MAX)

  
else:

  two = sorted(set(A))[-2]
  for i in range(N):
    if A[i] == MAX :
      print(two)
    else:
      print(MAX)
# Original solution
N=int(eval(input())) 
a=[int(eval(input())) for i in range(N)]
b=sorted(a)
n=0
while True:
    if n==a.index(max(a)):
        print((b[-2]))
    else:
        print((b[-1]))
    n+=1
    if n==N:
        break

# Optimized solution
import sys
input=sys.stdin.readline
N=int(eval(input())) 
a=[int(eval(input())) for i in range(N)]
b=sorted(a)
n=0
c=a.index(max(a))
for n in range(N):
    if n==c:
        print((b[-2]))
    else:
        print((b[-1]))
# Original solution
# coding:utf-8
def main():
    a = int(eval(input()))
    lists = []
    lists= [int(eval(input())) for _ in range(a)]

    temp = lists.copy()

    for i in range(a):
        lists = temp.copy()
        lists.pop(i)
        ans = max(lists)
        print(ans)

if __name__ == '__main__' :
    main()

# Optimized solution
# coding:utf-8
def main():
    a = int(eval(input()))
    lists= [int(eval(input())) for _ in range(a)]

    temp = lists.copy()
    first = max(temp)
    temp.remove(first)
    second = max(temp)

    for i in range(a):
        if lists[i] == first:
            print(second)
        else:
            print(first)

if __name__ == '__main__' :
    main()
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
B = list(A)
max_A = max(A)
for i in range(N):
    if max_A == A[i]:
        B.remove(A[i])
        print((max(B)))
        B = list(A)
    else:
        print(max_A)

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
max_A = max(A)
B = set(A)
if len(B) == 1 or A.count(max_A) >= 2:
    for i in range(N):
        print(max_A)
else:
    C = list(A)
    for i in range(N):
        if A[i] == max_A:
            C.remove(max_A)
            print((max(C)))
        else:
            print(max_A)
# Original solution
import copy

N = int(eval(input()))

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

max_a = max(A)

for i in range(N):
    max_l=0
    max_R=0
    if(A[:i]!=[]):
        max_l = max(A[:i])
    if(A[i+1:]!=[]):
        max_r = max(A[i+1:])
    print((max(max_r,max_l)))


# Optimized solution
import copy

N = int(eval(input()))

A = [int(eval(input())) for _ in range(N)]
B = sorted(A)
max_1 = B[-1]
max_2 = B[-2]

for i in range(N):
    if(A[i]==max_1):
        print(max_2)
    else:
        print(max_1)
# Original solution
import sys
input = sys.stdin.readline
 
def main():
    N = int(eval(input()))
    A = [int(eval(input())) for _ in range(N)]
    max_val = max(A)
    AA = A[:]
    AA.remove(max_val)
    second_max_val = max(AA)
    for a in A:
        if a != max_val:
            print(max_val)
        else:
            print(second_max_val)
 
if __name__ == '__main__':
    main()

# Optimized solution
import sys
input = sys.stdin.readline
 
def main():
  n = int(eval(input()))
  numList  = [int(eval(input())) for _ in range(n)]
  maxVal = max(numList)
  workList = numList[:]
  workList.remove(maxVal)
  secondVal = max(workList)
  for num in numList:
    if num != maxVal:
      print(maxVal)
    else:
      print(secondVal)
      
if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in [0] * N ]

for i in range(N):
  print((max(A[:i] + A[i+1:])))

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in [0] * N ]
M = max(A)
m = sorted(A)[-2]
for i in A:
  if i == M:
    print(m)
  else:
    print(M)
# Original solution
N=int(eval(input()))
AN=[int(eval(input())) for _ in range(N)]

for i in range(N):
    tmp=AN.copy()
    tmp.pop(i)
    print((max(tmp)))

# Optimized solution
N=int(eval(input()))
AN=[int(eval(input())) for _ in range(N)]
ret=max(AN)
ANc=sorted(AN,reverse=True)
ret2=ANc[1]

for i in range(N):
    if ret != AN[i]:
        print(ret)
    else:
        print(ret2)
# Original solution
n=int(eval(input()))
lst=[int(eval(input())) for i in range(n)]
for j in range(n):
  if j==0:
    print((max(lst[1:])))
  elif j==n-1:
    print((max(lst[:n])))
  else:
    a=max(lst[:j])
    b=max(lst[j+1:])
    print((max(a,b)))

# Optimized solution
n=int(eval(input()))
lst=[int(eval(input())) for i in range(n)]
a=max(lst)
aind=lst.index(a)
if aind==0:
  b=max(lst[1:])
elif aind==n-1:
  b=max(lst[:n-2])
else:
  tempa=max(lst[:aind])
  tempb=max(lst[aind+1:])
  b=max(tempa, tempb)
bind=lst.index(b)
for j in range(n):
  if j==aind:
    print(b)
  else:
    print(a)
# Original solution
import copy
N = int(eval(input()))
A = list()
for i in range(N):
    A.append(int(eval(input())))

for j in range(len(A)):
    Ai = copy.copy(A)
    del Ai[j]
    print((max(Ai)))

# Optimized solution
import copy
N = int(eval(input()))
A = list()
for i in range(N):
    A.append(int(eval(input())))
s = sorted(A)[::-1]
m1 = s[0]
m2 = s[1]

for j in A:
    if j == m1:
        print(m2)
    else:
        print(m1)
# Original solution
n = int(eval(input()))
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(eval(input())) for _ in range(n)]

First = max(A)
ind = A.index(First)
A[ind] = 0
Second = max(A)
A[ind] = First

for i in range(n):
    if A[i] == First:
        print(Second)
    else:
        print(First)
# Original solution
N = int(eval(input()))
A = []
for i in range(N):
        A.append(int(eval(input())))
m = max(A)
for i in range(N):
        if A[i] == m:
                A.remove(m)
                print((max(A)))
                A.insert(i,m)
        else:
                print(m)

# Optimized solution
N = int(eval(input()))
A = []
for i in range(N):
        A.append(int(eval(input())))
m = max(A)
n = A.index(m)
A.remove(m)
m1 = max(A)
for i in range(n):
        print(m)
print(m1)
for i in range(N-1-n):
        print(m)
# Original solution
n = int(eval(input()))
ls_a = [int(eval(input())) for _ in range(n)]

print((max(ls_a[1:])))
for i in range(1, n - 1):
	print((max(max(ls_a[:i]), max(ls_a[i+1:]))))
print((max(ls_a[:n])))

# Optimized solution
n = int(eval(input()))
ls_a = [int(eval(input())) for _ in range(n)]

ls_as = sorted(ls_a, reverse=True)
fst = ls_as[0]
snd = ls_as[1]

for i in range(n):
	if ls_a[i] != fst:
		print(fst)
	elif ls_a[i] == fst:
		print(snd)
# Original solution
N = int(eval(input()))
A = []
for i in range(N):
    A.append(int(eval(input())))

sort = sorted(A, reverse=True)
mx = sort[0]
mxn = sort[1]

for i in range(N):
    if A[i] == mx:
        print(mxn)
    else:
        print(mx)


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

mx, mxn = sorted(A, reverse=True)[:2]

for i in range(N):
    if A[i] == mx:
        print(mxn)
    else:
        print(mx)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]

for j in a:
    if j >= max(a):
        print((sorted(a)[-2]))
    else:
        print((max(a)))

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
b = a[:]
b.sort()

if b[n-1] == b[n-2]:
    for _ in range(n): 
        print((b[n-1]))
else:
    for j in a:
        if j >= b[n-1]:
            print((b[n-2]))
        else:
            print((b[n-1]))
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for n in range(N)]

maxA = max(A)
for n in range(N):
  if A[n] != maxA:
    print(maxA)
  else:
    a = A[n]
    A[n] = 0
    print((max(A)))
    A[n] = a

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for n in range(N)]
 
max_A = max(A)
max_index = A.index(max(A))

A[max_index] = 0
max_A2 = max(A)
A[max_index] = max_A

for n in range(N):
  if A[n] != max_A:
    print(max_A)
  else:
    print(max_A2)
# Original solution
n = int(eval(input()))
LA = [int(eval(input())) for i in range(n)]
LB = []
LB.extend(LA)
for i in range(n):
    del LB[i]
    print((max(LB)))
    LB = []
    LB.extend(LA)

# Optimized solution
n = int(eval(input()))
LA = [int(eval(input())) for i in range(n)]
LB = []
LB.extend(LA)
LA.sort()
z = LA[-1]
y = LA[-2]
for i in range(n):
    if LB[i] == z:
        print(y)
    else:
        print(z)
# Original solution
from collections import deque

num = int(eval(input()))

arr = deque([])

for i in range(num):
    arr.append(int(eval(input())))

for i in range(num):
    a = arr.popleft()
    print((max(list(arr))))
    arr.append(a)

# Optimized solution
from collections import deque

num = int(eval(input()))

arr = []

for i in range(num):
    arr.append(int(eval(input())))

arr0 = sorted(arr,reverse=True)
arr00 = arr0[0]
arr01 = arr0[1]

for i in range(num):
    if arr[i] != arr00:
        print(arr00)
    else:
        print(arr01)
# Original solution
N = int(eval(input()))
A = []
for _ in range(N):
    A.append(eval(input()))

B = A.copy()
B.remove(max(A))
second_max = max(B)
for i in range(N):
    if A[i] == max(A):
        print(second_max)
    else:
        print((max(A)))

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

B = sorted(A)
A_max, A_second_max = B[-1], B[-2] 
for i in A:
    if i == A_max:
        print(A_second_max)
    else:
        print(A_max)
# Original solution
n = int(eval(input()))
temp = []
for i in range(n):
	temp.append(int(eval(input())))

if n > 1:
	print((max(temp[1:n])))

	for i in range(1,n-1):
		print((max(max(temp[0:i]), max(temp[i+1:n]))))

	print((max(temp[0:n-1])))

else:
	print((temp[0]))

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

sort = temp[:]

sort.sort()

maximum = sort[-1]


for i in temp:
	if i != maximum:
		print(maximum)

	else:
		print((sort[-2]))
# Original solution
N=int(eval(input()))
a=[]
for _ in range(N):
    a.append(int(eval(input())))
for i in range(N):
    new=a[:i]+a[i+1:]
    print((max(new)))

# Optimized solution
N=int(eval(input()))
a=[]
for _ in range(N):
    a.append(int(eval(input())))
x=sorted(a,reverse=True)
m1=x[0]
m2=x[1]
for i in a:
    if i==m1:
        print(m2)
    else:
        print(m1)
# Original solution
N = int(eval(input()))
l = [None] * N
m = -float("inf")
m2 = -float("inf")
for i in range(N):
    l[i] = int(eval(input()))
    
    if (l[i] > m):
        m2 = m
        m = l[i]
    elif (l[i] > m2):
        m2 = l[i]


for el in l:
    if el == m:
        print(m2)
    else:
        print(m)    



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

m = -float("inf")
m2 = -float("inf")
max_idx = None
for i in range(N):
    el = int(eval(input()))    
    if (el > m):
        m2 = m
        m = el
        max_idx = i
    elif (el > m2):
        m2 = el


for i in range(max_idx):
    print(m)

print(m2)

for i in range(N-max_idx-1):
    print(m)
# Original solution
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)

# Override `input` function because `stdin.readline()` is 10x faster than built-in `input()`
input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(eval(input())) for _ in range(n)]


def main():
    n, = read_h()
    a = read_v(n)

    for i in range(n):
        arr = a[:i] + a[i + 1:]
        print((max(arr)))


if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)

# Override `input` function because `stdin.readline()` is 10x faster than built-in `input()`
input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(eval(input())) for _ in range(n)]


def main():
    n, = read_h()
    arr = read_v(n)

    max_asc = [0]
    for a in arr[:n - 1]:
        max_asc.append(max(max_asc[-1], a))
    #  print(max_asc)

    max_desc = [0]
    for a in arr[::-1][:n - 1]:
        max_desc.append(max(max_desc[-1], a))
    max_desc = max_desc[::-1]
    #  print(max_desc)

    #  assert len(max_asc) == len(max_desc)
    #  print(len(max_asc))

    for a, d in zip(max_asc, max_desc):
        print((max(a, d)))


if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
for i in range(N):
    x = A.pop(i)
    print((max(A)))
    A.insert(i,x)

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
m = max(A)
mindex = A.index(m)
for i in range(N):
    if(i != mindex):
        print(m)
    else:
        pop = A.pop(i)
        print((max(A)))
        A.insert(i,pop)
# Original solution
n = int(eval(input()))
ls = [int(eval(input())) for _ in range(n)]
p = 200000
ans = 0
if p>n:p=n

def cul(n, x):
    l = len(x)
    b = [x[i] for i in range(l)]
    b.pop(n)
    return max(b)
    
for i in range(n):
    s = cul(i,ls)
    print(s)

# Optimized solution
n = int(eval(input()))
ls = [int(eval(input())) for _ in range(n)]
ls_sort = sorted(ls,reverse=True)

for i in range(n):
    if ls[i] == ls_sort[0]:
        print((ls_sort[1]))
    else:
        print((ls_sort[0]))
# Original solution
import heapq
N = int(eval(input()))
A = [(-1) * int(eval(input())) for _ in range(N)]

for i in range(N):
    tmp_A = A[:i] + A[i + 1:]
    heapq.heapify(tmp_A)
    print(((-1) * heapq.heappop(tmp_A)))

# Optimized solution
def MI():
    return list(map(int, input().split()))

def LI():
    return list(map(int, input().split()))

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A)

for i in range(N):
    if A[i] == B[-1]:
        print((B[-2]))
    else:
        print((B[-1]))
# Original solution
n = int(eval(input()))
l = []
for i in range(n):
    l.append(int(eval(input())))

max_a = max(l)

for j in range(len(l)):
    if max_a == l[j]:
        tmp = l.pop(j)
        print((max(l)))
        l.insert(j, tmp)
    else:
        print(max_a)


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

l_b = sorted(l)
max_a = l_b[-1]
max_b = l_b[-2]

for j in range(len(l)):
    if max_a == l[j]:
        print(max_b)
    else:
        print(max_a)
# Original solution
n = int(eval(input()))
an = [int(eval(input())) for _ in range(n)]
    
for i in range(n):
        an_i= an[i]
        an[i] = 0
        print((max(an)))
        an[i] = an_i

# Optimized solution
n = int(eval(input()))
an = []
max_1 = 1
max_2 = 1
count = 1
max1_index = [0]
for i in range(n):
    a = int(eval(input()))
    if a > max_1:
        tmp = max_1
        max_1 = a
        count = 1
        max1_index = [i]
        max_2 = tmp
    elif a == max_1:
        count += 1
        max1_index.append(i)
    elif max_1 >  a > max_2:
        max_2 = a
    an.append(a)
if count == 1:
    for i in range(n):
        if i in max1_index:
            print(max_2)
        else:
            print(max_1)
else:
    for i in range(n):
        print(max_1)
# Original solution
N = int(eval(input()))
nums = [eval(input()) for i in range(N)]

for i in range(0, N):
    f_nums = nums[:i]
    l_nums = nums[i+1:]
    f_nums.extend(l_nums)
    print((max(f_nums)))

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

_nums = sorted(nums, reverse=True)
max1 = _nums[0]
max2 = _nums[1]
for i in range(0, N):
    if nums[i] == max1:
        print(max2)
    else:
        print(max1)
# Original solution
# -*- coding: utf-8 -*-

N = int(eval(input()))
A = [int(eval(input())) for x in range(N)]
ans = max(A)
for i in range(N):
    if A[i] == ans:
        print((max(A[:i] + A[i+1:])))
    else:
        print(ans)


# Optimized solution
# -*- coding: utf-8 -*-

N = int(eval(input()))
A = [int(eval(input())) for x in range(N)]
max1, max2 = sorted(A, reverse=True)[:2]
for i in range(N):
    if A[i] == max1:
        print(max2)
    else:
        print(max1)
# Original solution
n = int(eval(input()))
list = []
for i in range(n) :
    list.append(int(eval(input())))
for i in range(n) :
    sorted_list = sorted(list, reverse=True)
    idx = sorted_list.index(list[i])
    sorted_list.pop(idx)
    print((sorted_list[0]))


# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
sorted_list = sorted(a, reverse=True)
a_max = sorted_list[0]
a_sec = sorted_list[1]
for i in range(n) :
    if a[i] != a_max :
        print(a_max)
    else :
        print(a_sec)
# Original solution
import sys
input = sys.stdin.readline

def main():
	n = int(input().strip())
	a = [0] * n
	for i in range(n):
		a[i] = int(input().strip())
	b = sorted(a, reverse=True)
	first = b[0]
	second = b[1]
	for i in range(n):
		if a[i] == first:
			print(second)
		else:
			print(first)

if __name__ == '__main__':
	main()


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

def main():
	n = int(input().strip())
	a = [0] * n
	for i in range(n):
		a[i] = int(input().strip())
	l = [0] *(n+1)
	r = [0] *(n+1)
	for i in range(0, n):
		l[i+1] = max(l[i], a[i])
	for i in reversed(list(range(1, n))):
		r[i-1] = max(r[i], a[i])
	for i in range(n):
		print((max(l[i], r[i])))

if __name__ == '__main__':
	main()
# Original solution
import math
import copy
N = int(eval(input()))
A = [0] * N
for i in range(N):
    A[i] = int(eval(input()))
#修正ver
X = [0] * N
for i in range(N):
    B = [0] * N
    B = copy.copy(A)
    del B[i]
    max_item = max(B)
    X[i] = max_item
for i in range(N):
    print((X[i]))

# Optimized solution
import math
import copy
N = int(eval(input()))
A = [0] * N
for i in range(N):
    A[i] = int(eval(input()))
#修正ver
max_item = max(A)
count = 0
second_item = 0
for i in range(N):
    if A[i] == max_item:
        count += 1
    elif second_item < A[i]:
        second_item = A[i]
    if count > 1:
        break
X = [0] * N
judge = False
for i in range(N):
    if count > 1:
        judge = True
        break
    if A[i] == max_item:
        X[i] = second_item
    else:
        X[i] = max_item

if judge:
    for i in range(N):
        X[i] = max_item
for i in range(N):
    print((X[i]))
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
for i, num in enumerate(A):
    AA = [x for j, x in enumerate(A) if i != j]
    print((max(AA)))

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
A_max = max(A)
AA = A[:]
AA.remove(A_max)
A_max_2nd = max(AA)
for num in A:
    if num != A_max:
        print(A_max)
    else:
        print(A_max_2nd)
# Original solution
n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]

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

# Optimized solution
n = int(eval(input()))
A = [int(eval(input())) for _ in range(n)]
f_num = max(A)
A_c = A.copy()
A_c.remove(f_num)
s_num = max(A_c)

for a in A:
    if a == f_num:
        print(s_num)
    else:
        print(f_num)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
for i in range(N):
    A_1 = A.copy()
    A_1.pop(i)
    print((max(A_1)))

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
B = sorted(A,reverse=True)
if B[0] == B[1]:
    for i in range(N):
        print((B[0]))
else:
    for i in range(N):
        if A[i] == B[0]:
            print((B[1]))
        else:
            print((B[0]))
# Original solution
# 最大値と二番目に大きいやつをとっておく。最大値のときだけ二番目に大きいやつ採用
n = int(eval(input()))
arr = []
for i in range(n):
  t = int(eval(input())) 
  arr.append([i, t])

sorted_arr = list(sorted(arr, key = lambda x : x[1]))
biggest = sorted_arr[-1]
second_biggest = sorted_arr[-2]

for i in range(n):
  if i != biggest[0]:
    print((biggest[1]))
  else:
    print((second_biggest[1]))


# Optimized solution
n = int(eval(input()))
max_n = -1
semi_max_n = -1
max_idx = -1
for i in range(n):
    x = int(eval(input()))
    if x > max_n:
        max_n = x
        max_idx = i
    elif x >= semi_max_n:
        semi_max_n = x
for i in range(n):
    if i == max_idx:
        print(semi_max_n)
    else:
        print(max_n)
# Original solution
N = int(eval(input()))
A = []
for i in range(N):
    A.append(int(eval(input())))
for j in range(len(A)):
    remove = A.pop(j)
    print((max(A)))
    A.insert(j, remove)


# Optimized solution
N = int(eval(input()))
numbers = []
for i in range(N):
    numbers.append(int(eval(input())))
ordered = sorted(numbers, reverse = True)

for j in range(len(numbers)):
    if numbers[j] == ordered[0]:
        print((ordered[1]))
    else:
        print((ordered[0]))
# Original solution
import copy
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = copy.copy(a)
b.sort(reverse=True)
s = b[1]
m = max(a)

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

# Optimized solution
import copy
n = int(eval(input()))
a = []
for _ in range(n):
    a.append(int(eval(input())))
b = copy.copy(a)
a.sort(reverse=True)
for i in range(n):
    if b[i] == a[0]:
        print((a[1]))
    else:
        print((a[0]))
# Original solution
n=int(eval(input()))
l=[]
for i in range(n):
    l.append(int(eval(input())))
ll=l[:]
for j in range(len(l)):
    l=ll[:]
    l.pop(j)
    print((max(l)))


# Optimized solution
n=int(eval(input()))
l=[]
for i in range(n):
    l.append(int(eval(input())))
m=sorted(l)
m1=m[-1]
m2=m[-2]
c=l.count(m1)

for j in l:
    if j==m1:
        if c>1:
            print(m1)
        else:
            print(m2)
    else:
        print(m1)
# Original solution
n=int(eval(input()))
a=[]
for i in range(n):
    a.append(int(eval(input())))

m=max(a)
b=a[:]
b.remove(m)
m2=max(b)

for j in a:
    if j==m and a.count(m)>1:
        print(m)
    elif j==m and a.count(m)==1:
        print(m2)
    else:
        print(m)

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

m=max(a)
b=a[:]
b.remove(m)
m2=max(b)
x=a.count(m)

for j in a:
    if j==m and x>1:
        print(m)
    elif j==m and x==1:
        print(m2)
    else:
        print(m)