CodeEff/ECCO huggingface dataset:
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
max_a = max(A)
count = A.count(max_a)

if count > 1:
    for n in range(N):
        print(max_a)
else:
    for n in range(N):
        if A[n] == max_a:
            print((max(A[:n] + A[n+1:])))
            continue
        print(max_a)

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A, reverse=True)
for a in A:
    if a == B[0]:
        print((B[1]))
    else:
        print((B[0]))
# Original solution
import sys
input = sys.stdin.readline

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
amax = max(A)
amaxcnt = A.count(amax)

for i in range(N):
    a0 = A.pop(0)
    if a0 == amax and amaxcnt == 1:
        print((max(A)))
    else:
        print(amax)


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

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
amax = max(A)
amaxcnt = A.count(amax)

for i in range(N):
    ai = A[i]
    if ai == amax and amaxcnt == 1:
        A.pop(i)
        print((max(A)))
        A.insert(i, 0)
    else:
        print(amax)
# Original solution
import copy
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
for i in range(n):
    list2 = copy.copy(a)
    list2.pop(i)
    print((max(list2)))


# Optimized solution
import copy
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
sort_a = sorted(a,reverse=True)
for i in range(n):
    if sort_a[0] == a[i]:
        print((sort_a[1]))
    else:
        print((sort_a[0]))
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
for j in range(N):
    B = A[:j] + A[j+1:]
    print((max(B)))

# Optimized solution
N=int(eval(input()))
A=[int(eval(input())) for _ in range(N)]
B=sorted(A)[:N-1]
m=max(A)
n=A.index(max(A))
for i in range(N):
    if  i!=n:
        print(m)
    else:
        print((max(B)))
# Original solution
N = int(eval(input()))
list = [int(eval(input())) for i in range(N)]
if sorted(list)[-1] == sorted(list)[-2]:
    list2 = [max(list) for i in range(N)]
    print(("\n".join(map(str,list2))))
else:
    list2 = [max(list) for i in range(list.index(max(list)))]
    list2.append(sorted(list)[-2])
    list3 = [max(list) for j in range(list.index(max(list))+1,N)]
    list2.extend(list3)
    print(("\n".join(map(str,list2))))

# Optimized solution
N = int(eval(input()))
list = [int(eval(input())) for i in range(N)]
if sorted(list)[-1] == sorted(list)[-2]:
    list2 = [max(list)]*N
    print(("\n".join(map(str,list2))))
else:
    list2 = [max(list)]*list.index(max(list))
    list2.append(sorted(list)[-2])
    list3 = [max(list)]*(N-list.index(max(list))-1)
    list2.extend(list3)
    print(("\n".join(map(str,list2))))
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

if N == 2:
    print(("\n".join(map(str, A[::-1]))))
else:
    for i in range(N):
        if i == N - 1:
            print((max(A[:-1])))
        else:
            print((max(A[:i] + A[i+1:])))


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

if N == 2:
    print(("\n".join(map(str, A[::-1]))))
else:
    a = sorted(A)
    maxv1 = a[-1]
    maxi1 = A.index(maxv1)
    maxv2 = a[-2]

    for i in range(N):
        if i == maxi1:
            print(maxv2)        
        else:
            print(maxv1)
# Original solution
N=int(eval(input()))
L=[]
for i in range(N):
    L.append(int(eval(input())))

L_max=max(L)

for i in range(N):
    now=L[i]
    
    if now!=L_max:
        ans=L_max
        
    else:
        L_temp=L.copy()
        L_temp_p=L_temp.pop(i)
        ans=max(L_temp)
    
    print(ans)

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

L_max=max(L)

L_max_count=0
for l in L:
    if l==L_max:
        L_max_count+=1
    if L_max_count > 1:
        break

for i in range(N):
    now=L[i]
    
    if L_max_count > 1:
        ans=L_max
    
    elif now!=L_max:
        ans=L_max
        
    else:
        L_temp=L.copy()
        L_temp_p=L_temp.pop(i)
        ans=max(L_temp)
    
    print(ans)
# Original solution
N = eval(input())
a = []
for i in range(N):
        a.append(eval(input()))
B = max(a)
for i in range(N):
        if a[i] != B:
                print(B)
        else:
                b = a.pop(i)
                print((max(a)))
                a.insert(i,b)


# Optimized solution
N = eval(input())
a = []
for i in range(N):
        a.append(eval(input()))
b = sorted(a)
b0,b1 = b[-1],b[-2]
for i in range(N):
        if a[i]!=b0 :
                print(b0)
        else:
                print(b1)
# Original solution
n = int(eval(input()))
list =[int(eval(input())) for i in range(n)]
for i in range(n):
    if list[i] == max(list):
        print((sorted(list)[-2]))
    else:
        print((max(list)))

# Optimized solution
n = int(eval(input()))
list =[int(eval(input())) for i in range(n)]
m = max(list)
s = sorted(list)[-2]
for i in range(n):
    if list[i] == m:
        print(s)
    else:
        print(m)
# Original solution
n = int(eval(input()))
l = [int(eval(input())) for i in range(n)]
m = max(l)
for i in l:
    if i == m:
        la = l[:]
        la.remove(i)
        print((max(la)))
    else:
        print(m)

# Optimized solution
n = int(eval(input()))
l = [int(eval(input())) for i in range(n)]
la = sorted(l, reverse=True)
m1 = la[0]
m2 = la[1]
for i in l:
    if i == m1:
        print(m2)
    else:
        print(m1)
# Original solution
import sys
input = sys.stdin.readline
n=int(eval(input()))
a=[0]*n
for i in range(n):
    a[i]=int(eval(input()))

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

# Optimized solution
import sys
input = sys.stdin.readline
n=int(eval(input()))
a=[0]*n
for i in range(n):
    a[i]=int(eval(input()))
b=sorted(a)

for i in range(n):
    if a[i]!=b[-1]:
        print((b[-1]))
    else:
        print((b[-2]))
# Original solution
n = int(eval(input()))
num = []
for i in range(n):
  num.append(int(eval(input())))
  
for i in range(n):
  subnum = num[0:i] + num[i+1:n]
  subnum = sorted(subnum)
  print((subnum[n-2]))

# Optimized solution
n = int(eval(input()))
num = []
maxnum = 0
count = 1
for i in range(n):
  a = int(eval(input()))
  if a>maxnum:
    maxnum = max(maxnum,a)
    count = 1
  elif a==maxnum:
    count += 1
  num.append(a)
  
for i in range(n):
  if count>1:
    print(maxnum)
  else:
    if num[i]!=maxnum:
      print(maxnum)
    else:
      subnum = num[0:i] + num[i+1:n]
      subnum = sorted(subnum)
      print((subnum[n-2]))
# Original solution
n = int(eval(input()))
num = []
maxnum = 0
count = 1
for i in range(n):
  a = int(eval(input()))
  if a>maxnum:
    maxnum = max(maxnum,a)
    count = 1
  elif a==maxnum:
    count += 1
  num.append(a)
  
for i in range(n):
  if count>1:
    print(maxnum)
  else:
    if num[i]!=maxnum:
      print(maxnum)
    else:
      subnum = num[0:i] + num[i+1:n]
      subnum = sorted(subnum)
      print((subnum[n-2]))

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
a1 = sorted(a)
if a1[n-1]==a1[n-2]:
  flag = True ## true = have repeat
  maxone = a1[n-1]
else:
  flag = False ## false = no repeat
  maxone = a1[n-1]
  maxtwo = a1[n-2]
for i in range(n):
  if a[i]==maxone and flag==True: print(maxone)
  elif a[i]==maxone and flag==False: print(maxtwo)
  elif a[i]!=maxone: print(maxone)
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]
for i in range(n):
  b=a[:]
  del b[i]
  print((max(b)))

# Optimized solution
n=int(eval(input()))
a=[int(eval(input())) for _ in range(n)]
b=sorted(a)
for i in a:
  print((b[-2] if i==b[-1] else b[-1]))
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
for i in range(n):
    _a=a[:]
    _a.pop(i)
    print((max(_a)))


# Optimized solution
n=int(eval(input()))
t,s=0,0
a=[]
for i in range(n):
    _a=int(eval(input()))
    a.append(_a)
    if _a>t:
        t=_a
    elif _a==t or _a>s:
        s=_a
for _a in a:
    if _a==t:
        print(s)
    else:
        print(t)
# Original solution
n=int(eval(input()))
arr=[]

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

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

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

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

for i in range(n):
  if arr[i]==a:
    b=max(arr[:i]+arr[i+1:])
    break
    
for i in range(n):
  if arr[i]!=a:
    print(a)
  else:
    print(b)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for n in range(N)]

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

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for n in range(N)]
a1 = sorted(A)[-1]
a2 = sorted(A)[-2]

for a in A:
  if a == a1:
    print(a2)
  else:
    print(a1)
# Original 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]))


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

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

lst =[int(eval(input())) for i in range (N)]
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 = [int(eval(input())) for i in range(n)]
for i in range(n):
    dum = a_list[i]
    a_list[i] = 0
    print((max(a_list)))
    a_list[i] = dum


# Optimized solution
n = int(eval(input()))
a_list = [int(eval(input())) for i in range(n)]
a_list_sort = sorted(a_list)
a_list_max1 = max(a_list)
a_list_max2 = a_list_sort[-2]
for i in range(n):
    if a_list_max1 == a_list[i]:
        print(a_list_max2)
    else:
        print(a_list_max1)
# Original solution
N=int(eval(input()))

seq=[]

for i in range(N):
    a= int(eval(input()))
    seq.append(a)

import heapq

tmp=list([x*(-1) for x in seq])
heapq.heapify(tmp)

a=heapq.heappop(tmp)*(-1)
b=heapq.heappop(tmp)*(-1)

for j in range(N):
    if seq[j]==a:
        print(b)
    else:
        print(a)

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

b=a.copy()

import heapq
#これを加える！！！！
def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappop_max(heap):
    """Maxheap version of a heappop."""
    lastelt = heap.pop()    # raises appropriate IndexError if heap is empty
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt

b = sorted(b,reverse=True)

b1 = _heappop_max(b)
b2 = _heappop_max(b)

for i in range(n):
    if a[i]==b1:
        print(b2)
    else:
        print(b1)
# Original solution
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

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

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


# Optimized solution
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

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

SortedA = sorted(A)
A_first = SortedA[N-1]
A_second = SortedA[N-2]

for i in range(N):
    if A[i] == A_first:
        print(A_second)
    else:
        print(A_first)
# 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()))
numbers = [int(eval(input())) for i in range(n)]


m1,m2 = sorted(numbers, reverse=1)[:2]

b = [m2 if x==m1 else m1 for x in numbers]
for s in b:
    print(s)
# Original solution
n = int(eval(input()))
li = [int(eval(input())) for _ in range(n)]

for a, b in enumerate(li):
  li2 = li[a+1:] + li[:a]
  print((max(li2)))

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

mi = li.index(max(li))
m = max(li)

for a, b in enumerate(li):
  if a != mi:
    print(m)
  else:
    print((max(li[a+1:]+li[:a])))
# Original solution
N = int(eval(input()))
a = []
for i in range(N):
    b = int(eval(input()))
    a.append(b)

c = []
for j in range(N):
    c = a.copy()
    c.pop(j)
    print((max(c)))

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

c = sorted(a)
a1 = c[-1] 
a2 = c[-2]

for j in range(N):
    if a[j]==a1:
        print(a2)
    else:
        print(a1)
# Original solution
import sys
input = sys.stdin.readline

N=int(eval(input()))
a=[0]*N

max1=[0,0]
max2=[0,0]
for i in range(N):
    a=int(eval(input()))
    if max1[0]<=a:
        max2=max1
        max1=[a,i]
    elif max2[0]<=a:
        max2=[a,i]

for i in range(N):
    if i==max1[1]:
        print((max2[0]))
    else:
        print((max1[0]))

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

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

def main():
    mod=10**9+7
    N=I()
    A=[0]*N
    Mi=-1
    M=0
    for i in range(N):
        A[i]=I()
        if A[i]>M:
            Mi=i
            M=A[i]
            
    A[Mi]=0
    
    for i in range(N):
        if i!=Mi:
            print(M)
        else:
            print((max(A)))

main()
# Original solution
import copy

n = int(eval(input()))

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

for i in range(n):
    if lis[i] == m:
        tlis = copy.deepcopy(lis)
        tlis.remove(lis[i])
        print((max(tlis)))
    else:
        print(m)

# Optimized solution
import copy

n = int(eval(input()))

lis = []
for _ in range(n):
    lis.append(int(eval(input())))
    
slis = sorted(copy.deepcopy(lis), reverse=True)
    
m = max(lis)
s = sorted(slis, reverse=True)
s.remove(m)
sm = max(s)


for i in range(n):
    if lis[i] != m:
        print(m)
    else:
        print(sm)
# Original solution
N=int(eval(input()))
A=[]

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

for j in range(N):
  if j == A.index(max(A)) and A.count(max(A)) == 1:
    B=[i for i in A if i != max(A)]
    print((max(B)))
  else:
    print((max(A)))

# Optimized solution
N=int(eval(input()))
A=[]

for i in range(N):
  A.append(int(eval(input())))
B=sorted(A)
B=B[:len(B)-1]
C=[max(A)]*N
C[A.index(max(A))]=max(B)
for j in range(N):
  print((C[j]))
# Original solution
def resolve():
    n = int(eval(input()))
    aaa = [int(eval(input())) for _ in range(n)]
    maxa = max(aaa)
    for i in range(n):
        if maxa == aaa[i]:
            print((max(aaa[:i]+aaa[i+1:])))
        else:
            print(maxa)
resolve()

# Optimized solution
def resolve():
    n = int(eval(input()))
    aaa = [int(eval(input())) for _ in range(n)]
    sorta = sorted(aaa, reverse=True)
    maxa = sorta[0]
    seconda = sorta[1]
    for i in range(n):
        if maxa == aaa[i]:
            print(seconda)
        else:
            print(maxa)
resolve()
# Original solution
import copy

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = []
for i in range(n):
  b = copy.copy(a)
  b.pop(i)
  print((max(b)))
  b = []

# Optimized solution
import copy

n = int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = sorted(copy.copy(a))
ma = b[-1]
mi = b[-2]
for i in range(n):
  if a[i] == ma:
    print(mi)
  else:
    print(ma)
# Original solution
n = int(eval(input()))
A = [int(eval(input())) for i in range(n)]
m = str(max(A))
ANS = []

for i in range(n):
    if i == A.index(max(A)):
        ans = A[:]
        ans.pop(i)
        ANS.append(str(max(ans)))
    else:
        ANS.append(m)

print(('\n'.join(ANS)))

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

a_max = B[len(B)-1]
a_next = B[len(B)-2]

for i in range(n):
    if A[i] != a_max:
        print(a_max)
    else:
        print(a_next)
# Original solution
N=int(eval(input()))
A=[]
for i in range(N):
  A.append(int(eval(input())))

maxA=max(A)

for i in range(N):
  if A[i]<maxA:
    print(maxA)
  else:
    B=A[:]
    del B[i]
    print((max(B)))


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

maxA=max(A)
countNumber=A.count(maxA)

for i in range(N):
  if A[i]<maxA:
    print(maxA)
  elif countNumber>1:
    print(maxA)
  else:
    B=A[:]
    del B[i]
    print((max(B)))
# Original solution
n = int(eval(input()))
numlist = []
for i in range(n):
    numlist.append(int(eval(input())))
for i in range(n):
    tmplist = numlist.copy()
    del tmplist[i]
    print((max(tmplist)))

# Optimized solution
n = int(eval(input()))
numlist = []
for i in range(n):
    numlist.append(int(eval(input())))
argmax = numlist.index(max(numlist))
maxnum = max(numlist)
del numlist[argmax]
secondnum = max(numlist)
                       
for i in range(argmax):
    print (maxnum)
print (secondnum)
for i in range(argmax+1,n):
    print (maxnum)
# Original solution
n = int(eval(input()))
a = ['']*n
for i in range(n):
    a[i] = int(eval(input()))

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

# Optimized solution
n = int(input())
a = ['']*n
for i in range(n):
    a[i] = int(input())
_a = sorted(a, reverse=1)
a_max = _a[0]
a_second = _a[1]
ans = [a_max] * n

for i in range(n):
    if a[i] == a_max:
        ans[i] = a_second
    else:
        pass

print(*ans, sep='\n')
# Original solution
n = int(eval(input()))

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

print((max(a[1:])))

for i in range(1, n-1):
    a1 = max(a[:i])
    a2 = max(a[i+1:])
    max_a = a1 if a1 > a2 else a2
    print(max_a)
    
print((max(a[:-1])))

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

a = [int(eval(input())) for i in range(n)]
 
b = sorted(a, reverse=True)
 
 
for ai in a:
    if ai == b[0]:
        print((b[1]))
    else:
        print((b[0]))
# Original solution
import heapq
import copy

N=int(eval(input()))
A=[-int(eval(input())) for i in range(N)]
#print(N,A)

for j in range(N):
    copy_A=copy.copy(A)
    item=copy_A.pop(j)  #負
    #print(item)
    heapq.heapify(copy_A)
    #print(copy_A)
    MAX=-copy_A[0]  #正
    print(MAX)





# Optimized solution
import copy

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

A_max=max(A)
ind_max=A.index(A_max)
B=copy.copy(A)
B.remove(A_max)
B_max=max(B)

for i in range(N):
    if A[i]!=A_max:
        print(A_max)
    else:
        print(B_max)
# Original solution
import copy

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

A_max=max(A)
ind_max=A.index(A_max)
B=copy.copy(A)
B.remove(A_max)
B_max=max(B)

for i in range(N):
    if A[i]!=A_max:
        print(A_max)
    else:
        print(B_max)


# Optimized solution
import copy

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

A_max=max(A)
ind_max=A.index(A_max)
B=copy.copy(A)
B.remove(A_max)
B_max=max(B)

for i in range(N):
    if i!=ind_max:
        print(A_max)
    else:
        print(B_max)
# Original solution
n = int(eval(input()))

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

for i in range(len(list_A)):
    list_check = list_A[:i] + list_A[i+1:]
    print((max(list_check)))

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

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

#リスト内の最大の値を格納
max_val = max(list_A)

#リスト内の最大の値の位置を格納
for i in range(len(list_A)):
    if list_A[i] == max_val:
        max_val_position = i
        break

#リスト内のから最大の要素を除いた後の，最大の要素
max_val_2 = max(list_A[:max_val_position] + list_A[max_val_position+1:])

for i in range(len(list_A)):
    
    #リスト内の最大の数が除かれたときは二番目に大きい数を出力する
    if i == max_val_position:
        print(max_val_2)
    else:
        print(max_val)
# Original solution
# C
N = int(eval(input()))
A=[]
for i in range(N):
    A.append(int(eval(input())))
for i in range(len(A)):
    temp = A[i]
    A[i] = 0
    print((max(A)))
    A[i] = temp

# Optimized solution
# C
N = int(eval(input()))
A=[]
for i in range(N):
    A.append(int(eval(input())))
max1 = max(A)#一番手
max_index = A.index(max1)#index
A.remove(max1)
max2 = max(A)

for i in range(N):
    if i==max_index:
        print(max2)
    else:
        print(max1)
# Original solution
#134

N = int(eval(input()))
A_max = 0
A_max_s = 0
flag = 0
A = []

for i in range(N):
    a = int(eval(input()))
    A.append(a)
    if a > A_max:
        A_max_s = A_max
        A_max = a
        ind_max = i
        flag = 0
    elif A_max_s < a < A_max:
        A_max_s = a
    elif a == A_max:
        flag += 1
        
if flag >= 1:
    for i in range(N):
        print(A_max)
elif flag == 0:
    for i in range(N):
        if i != ind_max:
            print(A_max)
        else:
            print(A_max_s)

    
    

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
A_copy = A[:]
A_copy.sort()
# print(A, A_sort)
A_max = A_copy[len(A_copy)-1]
A_second = A_copy[len(A_copy)-2]
for i in range(N):
    if A[i] != A_max:
        print(A_max)
    else:
        print(A_second)
# Original solution
n = int(eval(input()))
a = [0]*n
for i in range(n):
    a[i] = int(eval(input()))

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

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

b = sorted(a)
for x in a:
    print(( b[-2] if x == b[-1] else b[-1] ))
# Original solution
N = int(eval(input()))
data = [ int(eval(input())) for _ in range(N) ]
s_data = sorted(data)

for i in range(N):
    if s_data[N-1] == data[i]:
        print((s_data[N-2]))
    else:
        print((s_data[N-1]))


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

data_s = sorted(data)

for d in data:
  if d == data_s[-1]:
    print((data_s[-2]))
  else:
    print((data_s[-1]))

# print(data)
# print(data_s)
# Original solution
N = int(eval(input()))
A = []
for i in range(N):
  A.append(int(eval(input())))
for i in range(N):
  a = A.copy()
  del a[i]
  print((max(a)))

# Optimized solution
N = int(eval(input()))
A = []
for i in range(N):
  A.append(int(eval(input())))
a = sorted(A)
max = a[-1]
if max == a[-2]:
  for i in range(N):
    print(max)
else:
  n = A.index(max)
  for i in range(N):
    if i == n:
      print((a[-2]))
      continue
    print(max)
# Original solution
a = int(eval(input()))
b = [int(eval(input())) for _ in range(a)]
c = [0] * a
c[0] = b[0]
c[1] = max(b[1], c[0])
d = [0] * a
d[0] = b[-1]
d[1] = max(b[-2], d[0])
for i in range(2, len(b)):
    c[i] = max(c[i-1], b[i])
    d[i] = max(d[i-1], b[-i-1])
c.insert(0, 0)
d.insert(0, 0)
for i in range(len(c)-1):
    print((max(c[i], d[-i-2])))


# Optimized solution
a = int(eval(input()))
b = [int(eval(input())) for _ in range(a)]
c = b.copy()
c = sorted(c, reverse=True)
for i in b:
    if i == c[0]:
        print((c[1]))
    else:
        print((c[0]))
# Original solution
# C - Exception Handling

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
for i in range(N):
    print((max(A[:i] + A[i + 1:])))

# Optimized solution
# C - Exception Handling

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
mx1 = sorted(A)[-1]
mx2 = sorted(A)[-2]
for i in range(N):
    if A[i] != mx1:
        print(mx1)
    else:
        print(mx2)