CodeEff/ECCO huggingface dataset:
# Original solution
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
A,B=sorted(a,reverse=True)[0:2]
for i in range(n):
    if i==a.index(max(a)):
        print(B)
    else:
        print(A)

# Optimized solution
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
A,B=sorted(a,reverse=True)[0:2]
for i in range(n):
    if a[i]==A:
        print(B)
    else:
        print(A)
# Original solution
n = int(eval(input()))
li = []
for i in range(n):
    li.append(int(eval(input())))
for i in range(n):
    k = li[i]
    li[i] = 0
    print((max(li)))
    li[i] = k

# Optimized solution
n = int(eval(input()))
li = []
for i in range(n):
    li.append(int(eval(input())))
k = max(li)
l = li.index(k)
for i in range(n):
    if i == l:
        li[i] = 0
        print((max(li)))
    else:
        print(k)
# Original solution
import copy
n = int(eval(input()))
nums = []
for i in range(n):
  nums.append(int(eval(input())))
#print(nums)  

for i in range(n):
  new_list = copy.copy(nums)
  del new_list[i]
  print((max(new_list)))

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

nums_sorted = sorted(nums)  
biggest = nums_sorted[-1]
second_biggest = nums_sorted[-2]
max_ind = nums.index(biggest)

if nums.count(biggest) == 1:
  for i in range(n):
    if i == max_ind:
      print(second_biggest)
    else:
      print(biggest)
else:
  for i in range(n):
    print(biggest)
# Original solution
import copy
n = int(eval(input()))
al = []
for _ in range(n):
    al.append(int(eval(input())))

alcopy = copy.deepcopy(al)
alcopy.sort()
for a in al:
    if a != max(al):
        print((max(al)))
    else:
        print((alcopy[-2]))

# Optimized solution
import copy
n = int(eval(input()))
lst =[]
for i in range(n):
    x = int(eval(input()))
    lst.append(x)

lst2 = copy.deepcopy(lst)
lst2.sort()
max = max(lst2)
for x in lst:
    if x == max:
        print((lst2[-2]))
    else:
        print(max)
# Original solution
# -*- coding: utf-8 -*-

n = int(eval(input()))

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

a_sorted = sorted(a, reverse=True)

for i in range(n):
    index = a_sorted.index(a[i])
    if a[i] == a_sorted[0]:
        print((a_sorted[1]))
        continue

    print((a_sorted[0]))


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

n = int(eval(input()))

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

a_sorted = sorted(a, reverse=True)

for i in range(n):
    if a[i] == a_sorted[0]:
        print((a_sorted[1]))
        continue

    print((a_sorted[0]))
# Original solution
n = int(eval(input()))
a = []
for _ in range(n):
    a.append(int(eval(input())))

for i in range(n):
    t = a[i]
    a.remove(t)
    print((max(a)))
    a.insert(i,t)

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

for t in a:
    if t == mx:
        print(mx2)
    else:
        print(mx)
# Original solution
N=int(eval(input()))
a=[]
for i in range(N):
    a.append(int(eval(input())))
for j in range(N):
    k=a.pop(j)
    mx=a[0]
    for l in range(1,N-1):
        mx=max(mx,a[l])
    print(mx)
    a.insert(j,k)

# Optimized solution
N=int(eval(input()))
mx=int(eval(input()))
a=[mx]
for i in range(N-1):
    l=int(eval(input()))
    a.append(l)
    mx=max(mx,l)
num=a.index(mx)
a.remove(mx)
mx2=a[0]
for j in range(1,N-1):
    mx2=max(mx2,a[j])
for k in range(N):
    if k==num:
        print(mx2)
    else:
        print(mx)
# Original solution
import copy
n = int(eval(input()))
a_list = [ int(eval(input())) for _ in range(n)]
for i, a in enumerate(a_list):
  tmp_list = copy.copy(a_list)
  tmp_list.pop(i)
  max_val = max(tmp_list)
  print(max_val)
  

# Optimized solution
import copy
n = int(eval(input()))
a_list = [ int(eval(input())) for _ in range(n)]
max_val = max(a_list)
index = [a_list.index(max_val)]
tmp_list = copy.copy(a_list)
for i, a in enumerate(a_list):
  if 2 <= len(index):
    print(max_val)
  elif i in index:
    tmp_list.pop(i)
    print((max(tmp_list)))
    tmp_list = copy.copy(a_list)
  else:
    print(max_val)
# Original solution
def main():
    n = int(eval(input()))
    a_list = [int(eval(input())) for _ in range(n)]
    a_sorted = sorted(a_list)
    a_first = a_sorted[-1]
    a_second = a_sorted[-2]

    for a in a_list:
        if a == a_first:
            print(a_second)
        else:
            print(a_first)


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    n = int(eval(input()))
    a_list = [int(eval(input())) for _ in range(n)]
    a_sorted = sorted(a_list)
    a_first = a_sorted[-1]
    a_second = a_sorted[-2]
    a_count = a_list.count(a_first)

    if a_count >= 2:
        for a in a_list:
            print(a_first)
    else:
        for a in a_list:
            if a == a_first:
                print(a_second)
            else:
                print(a_first)


if __name__ == '__main__':
    main()
# Original solution
N=int(eval(input()))
A = [int(eval(input())) for i in range(N)]
for i,a in enumerate(A):
  B = A[:]
  B[i]=0
  print((max(B)))


# Optimized solution
N=int(eval(input()))
A = [int(eval(input())) for i in range(N)]
maxval = max(A)
argmaxval = A.index(maxval)
for i,a in enumerate(A):
  if i==argmaxval:
    B = A[:]
    B[i]=0
    print((max(B)))
  else:
    print(maxval)
# Original solution
n=int(eval(input()))
li=[int(eval(input())) for _ in range(n)]

max_=0
for _ in range(n-1):
  res=li[0]
  del li[0]
  ans=max(li)
  if ans>max_:
    print(ans)
  else:
    print(max_)
  if res>max_:
    max_=res
    
print(max_)

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

lis=sorted(li)
max1=lis[-1]
max2=lis[-2]
for i in li:
  if(i==max1):
    print(max2)
  else:
    print(max1)
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
max_a = max(a)
for i in range(n):
    if max_a == a[i]:
        a[i] = 0
        print((max(a)))
        a[i]=max_a
    else: print(max_a)

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
a_1 = max(a)
a_2 = sorted(a)[-2]
for i in a:
    if i != a_1: print(a_1)
    else: print(a_2)
# Original solution
n = int(eval(input()))
a = []
a_sorted = []
tmp = 0
tmpp = 0

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

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 i in range(n)]

sorted_a = sorted(a)

max_a = sorted_a[-1]
max_a_r = sorted_a[-2]

for i in range(n):
    if a[i] == max_a:
        print(max_a_r)
    else:
        print(max_a)
# Original solution
n=int(eval(input()))
a=[]
m=0
for i in range(n):
    a.append(int(eval(input())))
for i in range(n):
    if a[i]!=max(a):
        print((max(a)))
    else:
        m=a[i]
        a[i]=1
        print((max(a)))
        a[i]=m

# Optimized solution
n=int(eval(input()))
a=[]
m1=0
m2=0
for i in range(n):
    a.append(int(eval(input())))
    A=a[i]
    if a[i]>m1:
        m2=m1
        m1=a[i]
        index=i
    elif m1==a[i]:
        m2=a[i]
    elif a[i]>m2:
        m2=a[i]
for i in range(n):
    if i==index:
        print(m2)
    else:
        print(m1)
# Original solution
n = int(eval(input()))
a_list = [int(eval(input())) for _ in range(n)]
for i in range(n):
    cp_list = a_list.copy()
    cp_list[i] = 0
    print((max(cp_list)))
    

# Optimized solution
n = int(eval(input()))
a_list = [int(eval(input())) for _ in range(n)]
cp_list = a_list.copy()
cp_list.sort()
second_ans = cp_list[-2]
ans = cp_list[-1]
for i in range(n):
    if a_list[i] == ans:
        print(second_ans)
    else:
        print(ans)
# Original solution
N= int(eval(input()))
A=[]
for x in range(0,N):
    A.append(int(eval(input())))
B=sorted(A)
for x in range(0,N):
    if A[x]==B[N-1]:
        print((B[N-2]))
    else:
        print((B[N-1]))


# Optimized solution
n=int(eval(input()))
a=int(eval(input()))
f,v,w=0,a,a
a=int(eval(input()))
if a>=v:
    w,v,f=v,a,1
else:
    w=a
for i in range(2,n):
    a=int(eval(input()))
    if a>=v:
        w,v,f=v,a,i
    elif a>=w:
        w=a
for i in range(n):
    if i==f:
        print(w)
    else:
        print(v)
# Original solution
N = int(eval(input()))
A = []
for i in range(N):
    A.append(int(eval(input())))
    
MAX1 = max(A)
MAX2 = -1
for i in range(N):
    if i != A.index(MAX1):
        MAX2 = max(MAX2,A[i])
        
if MAX1 == MAX2:
    for i in range(N):
        print(MAX1)
else:
    for i in range(N):
        if i == A.index(MAX1):
            print(MAX2)
        else:
            print(MAX1)
            
    

# Optimized solution
N = int(eval(input()))
A = []
for i in range(N):
    A.append(int(eval(input())))
    
MAX1 = max(A)
MAX2 = -1
index = A.index(MAX1)
for i in range(N):
    if i != index:
        MAX2 = max(MAX2,A[i])
        
if MAX1 == MAX2:
    for i in range(N):
        print(MAX1)
else:
    for i in range(N):
        if i == index:
            print(MAX2)
        else:
            print(MAX1)
# Original solution
N = int(eval(input()))
A = []
for n in range(N):
    A.append(int(eval(input())))

max_A = sorted(A)[-1]
second_A = sorted(A)[-2]

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

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

max_A = sorted(A)[-1]
second_A = sorted(A)[-2]

for n in range(N):
    if A[n] != max_A:
        print(max_A)
    else:
        print(second_A)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
M = max(A)

for i in range(N):
    if M == A[i]:
        A[i] *= -1
        print((max(A)))
        A[i] *= -1
    else:
        print(M)

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

S = sorted(A)
M1 = S[-1]
M2 = S[-2]

for i in range(N):
    if A[i] == M1:
        print(M2)
    else:
        print(M1)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
max = [0]*N

for i in range(N):
    for j in range(N):
        if i != j:    
            if max[i] < A[j]:
                max[i] = A[j]

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

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
B = sorted(A, reverse=True)

for i in range(N):
    if B[0] == A[i]:
        print((B[1]))
    else:
        print((B[0]))
# Original solution
import copy
n = int(eval(input()))
a = []
for i in range(n):
    a.append(int(eval(input())))
for i in range(n):
    tmp = copy.copy(a)
    tmp[i] = 0
    print((max(tmp)))

# Optimized solution
import copy
n = int(eval(input()))
a = []
for i in range(n):
    a.append(int(eval(input())))
tmp = copy.copy(a)
tmp.sort()
max_num = tmp[-1]
min_num = tmp[-2]
for i in range(n):
    if a[i] == max_num:
        print(min_num)
    else:
        print(max_num)
# Original solution
N=int(eval(input()))
A=[eval(input()) for i in range(N)]
for i in range(N):
    D=A[0:i]+A[i+1:]
    print((max(D)))
    

# Optimized solution
N=int(eval(input()))
A=[int(eval(input())) for i in range(N)]
D=sorted(A)
num=max(D)
num2=D[-2]
for i in range(N):
    if A[i]==num:
        print(num2)
    else:
        print(num)
# Original solution
N = int(eval(input()))
import copy
A = [int(eval(input())) for _ in range(N)]
for i in range(N):
    B = copy.copy(A)
    B.remove(B[i])
    print((max(B)))

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

import copy
B = copy.copy(A)
B.remove(a)

for j in range(N):
    if j == i:
        print((max(B)))
    else:
        print(a)
# Original solution
import copy
n=eval(input())
n=int(n)
A=[]
for i in range(n):
  A.append(eval(input()))
a=[int(j) for j in A]
a_copy=copy.deepcopy(a)
answer=[]
for i in range(n):
  a.pop(i)
  answer.append(max(a))
  a=copy.deepcopy(a_copy)
for k in range(n):
  print((answer.pop(0)))

# Optimized solution
import copy
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
a_copy=copy.deepcopy(a)
a_copy=sorted(a_copy)
max_num=a_copy[-1]
sec_num=a_copy[-2]
answer=[]
for j in range(len(a)):
  if a[j]==max_num:
    answer.append(sec_num)
  else:
    answer.append(max_num)
for k in range(len(answer)):
  print((answer[k]))
# Original solution
n=int(eval(input()))
a=[int(eval(input()))for _ in range(n)]
b=sorted(a)
for i in range(n):
    if a[i]==max(a):
        print((b[-2]))
    else:
        print((max(a)))

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

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

for i in range(N):
  if A[i] != M:
    print(M)
  else:
    a = A[:i] + A[i+1:]
    print((max(a)))

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
a = sorted(set(A))
max_count = A.count(a[-1])

for i in range(N):
  if len(a) > 1:
    if A[i] != a[-1]:
      print((a[-1]))
    else:
      if max_count > 1:
        print((a[-1]))
      else:
        print((a[-2]))
  else:
    print((a[-1]))
# Original solution
def main():
    n = int(eval(input()))
    a = [int(eval(input())) for i in range(n)]
    for i in range(n):
        d = sorted(a, reverse=True)
        if d[0] == a[i]:
            print((d[1]))
        else:
            print((d[0]))
            
if __name__ == '__main__':
    main()

# Optimized solution
def main():
    n = int(eval(input()))
    a = [int(eval(input())) for i in range(n)]
    d = sorted(a, reverse=True)
    for i in range(n):    
        if d[0] == a[i]:
            print((d[1]))
        else:
            print((d[0]))

if __name__ == '__main__':
    main()
# Original solution
n=int(eval(input()))
l =[]
for i in range(n):
        a = int(eval(input()))
        l.append(a)
        b = max(l)
for i in range(n):
        if l[i] == b:
                del l[i]
                print((max(l)))
                l.insert(i,b)

        else:
                print(b)


# Optimized solution
n=int(eval(input()))
a = [int(eval(input())) for _ in range(n)]
b = max(a)
c = a.index(b)
for i in range(n):
        if i == c:
                print((max(sorted(a)[:n-1])))
        else:
                print(b)
# Original solution
n = int(eval(input()))
ls = [int(eval(input())) for i in range(n)]
for j in range(n):
    a = ls[0:j] + ls[j+1:]
    print((max(a)))

# Optimized solution
import sys
n = int(eval(input()))
ls = [int(eval(input())) for _ in range(n)]
mx = max(ls)
c = ls.count(mx)
new = ls[:]
new.remove(mx)
nx = max(new)
if c > 1:
    for _ in range(n):
        print(mx)
    sys.exit()
for i in ls:
    if i == mx:
        print(nx)
    else:
        print(mx)
# Original solution
N = int(eval(input()))
A = []
for i in range(N):
  A.append(int(eval(input())))

#num = [0]*(N+1)
#for i in range(N):
#num[i+1] = num[i] + A[i]

for j in range(N):
  result = A[:j]+A[j+1:]
  print((max(result)))

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

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

ans=0
for i in range(N):
  ans=max(left[i],right[i+1])
  print(ans)
# Original solution
n = int(eval(input()))
a = tuple(int(eval(input())) for i in range(n))
x = a.count(max(a))
if 2 <= x:
    for i in range(n):
        print((max(a)))
else:
    for i in range(n):
        if a[i] != max(a):
            print((max(a)))
        else:
            print((max(a[:i] + a[i+1:])))

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
b = tuple(a)
a.sort()
for i in b:
    if i == a[n-1]:
        print((a[n-2]))
    else:
        print((a[n-1]))
# Original solution
n = int(eval(input()))
num = list(int(eval(input())) for i in range(n))

i = 0

while i != n:
  t = num.pop(0)
  print((max(num)))
  num.append(t)
  i += 1


# Optimized solution
n = int(eval(input()))
num = list(int(eval(input())) for i in range(n))
test = sorted(num, reverse=True)
i = 0

for i in range(n):
  if(num[i] == test[0]):
    print((test[1]))
  else:
    print((test[0]))
# Original solution
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(eval(input()))
    a = [int(eval(input())) for _ in range(n)]
    max_a, max_a2 = sorted(a, reverse=True)[:2]
    print(('\n'.join(map(str, [max_a if i != max_a else max_a2 for i in a]))))

if __name__ == '__main__':
    main()


# Optimized solution
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(eval(input()))
    a = tuple(map(int, [eval(input()) for _ in range(n)]))
    max_a, max_a2 = sorted(a, reverse=True)[:2]
    print(('\n'.join(map(str, [max_a if i != max_a else max_a2 for i in a]))))

if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
a = []
for _ in range(n):
    a.append(int(eval(input())))

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

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

sorted_a = sorted(a)
first = sorted_a[-1]
second = sorted_a[-2]
first_place = a.index(first)
for i in range(n):
    if first == second:
        print(first)
    else:
        if i == first_place:
            print(second)
        else:
            print(first)
# Original solution
n = int(eval(input()))
an = []
for _ in range(n):
  an.append(int(eval(input())))
maxl = [an[0]]
maxr = [an[-1]]
for a in an[1:]:
  maxl.append(max(maxl[-1], a))
for a in an[:-1][::-1]:
  maxr.insert(0, max(maxr[0], a))

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

# Optimized solution
n = int(eval(input()))
an = []
for _ in range(n):
  an.append(int(eval(input())))
maxl = [an[0]]
maxr = [an[-1]]
for a in an[1:]:
  maxl.append(max(maxl[-1], a))
for a in an[:-1][::-1]:
  maxr.append(max(maxr[-1], a))
maxr = maxr[::-1]

print((maxr[1]))
for i in range(1, n-1):
  print((max(maxl[i-1], maxr[i+1])))
print((maxl[n-2]))
# Original solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
for i in range(n):
    a_tmp = a[:]
    a_tmp[i] = 0
    print((max(a_tmp)))

# Optimized solution
n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
maxvalue = max(a)
maxindex = a.index(max(a))
for i in range(n):
    if i != maxindex:
        print(maxvalue)
    else:
        a_tmp = a[:]
        a_tmp.pop(maxindex) 
        print((max(a_tmp)))
# Original solution
n=int(eval(input()))
a=[]
for i in range(n):
  a.append(int(eval(input())))
print((max(a[1:])))
for j in range(1,n-1):
  b=a[:j]+a[j+1:]
  print((max(b)))
print((max(a[:n])))

# Optimized solution
n=int(eval(input()))
a=[]
for i in range(n):
  a.append(int(eval(input())))
m=max(a)
x=[i for i, x in enumerate(a) if x == m]
if(len(x)>=2):
  for i in range(n):
    print(m)
else:
  a.remove(m)
  M=max(a)
  for i in range(n):
    if(i==x[0]):
      print(M)
    else:
      print(m)
# Original solution
# -*- coding: utf-8 -*-

import math

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

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


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

import math

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

    value = sorted(A)
    first = value[N-1]
    second = value[N-2]


    # print(A)

    for i in range(N):
        if A[i] != first:
            print(first)
        else:
            print(second)
# Original solution
N = int(eval(input()))
lst = [int(eval(input())) for _ in range(N)]


for j in range(len(lst)):
    if max(lst) != lst[j]:
        print((max(lst)))
    else:
        print((sorted(lst)[-2]))



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

mx = max(lst)
clst = sorted(lst)
mx2 = clst[-2]

for j in range(N):
    if mx != lst[j]:
        print(mx)
    else:
        print(mx2)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]


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

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
sort_A = sorted(A)
max_A = sort_A[-1]

for i in A:
    if max_A != i:
        print(max_A)
    else:
        print((sort_A[-2]))
# Original solution
# -*- coding: utf-8 -*-
import copy

# input
N = int(eval(input()))
A = list()
for _ in range(N):
    A.append(int(eval(input())))

# solve & output
for i in range(N):
    tmp = copy.copy(A)
    del tmp[i]
    print((max(tmp)))


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

# input
N = int(eval(input()))
A = list()
for _ in range(N):
    A.append(int(eval(input())))

# solve & output
ans = copy.copy(A)
ans.sort()
m = ans[-1]
for i in range(N):
    if A[i] != m:
        print(m)
    else:
        print((ans[N - 2]))
# Original solution
A = [int(eval(input())) for i in range(int(eval(input())))]
max_A = max(A)
for i in A:
    if i == max_A:
        print((sorted(A)[-2]))
    else:
        print(max_A)


# Optimized solution
A = [int(eval(input())) for i in range(int(eval(input())))]
first = max(A)
second = sorted(A)[-2]
for i in A:
    if i == first:
        print(second)
    else:
        print(first)
# Original solution
n=int(eval(input()))
a = [int(eval(input())) for i in range(n)]
for i in range(n):
  b=a[i]
  a[i]=0
  print((max(a)))
  a[i]=b

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

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()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A)

for a in A:
    if a==max(A):
        print((B[-2]))
    else:
        print((B[-1]))

# Optimized solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
B = sorted(A)
M0 = B[-1]
M1 = B[-2]

for a in A:
    if a==M0:
        print(M1)
    else:
        print(M0)
# Original solution
n=int(eval(input()))
lis=list(int(eval(input())) for _ in range(n))
for i in range(n):
    ans=max(max(lis[:i],lis[i+1:n]))
    print(ans)

# Optimized solution
n=int(eval(input()))
lis=list(int(eval(input())) for _ in range(n))
lis2=lis
lis2=sorted(lis2)
MAX=lis2[-1]
second=lis2[-2]
if lis.count(MAX) ==1:
    lis3=[MAX for _ in range(n)]
    lis3[lis.index(MAX)]=second
    for i in range(n):
        print((lis3[i]))
        
else:
    for _ in range(n):
        print(MAX)
# Original solution
n=eval(input())
n=int(n)
l=[]
for i in range(n):
    x=eval(input())
    x=int(x)
    l.append(x)
ans=max(l)
for i in range(n):
    
    if l[i]==ans:
        del l[i]
        print((max(l)))
        l.append(0)
        continue
    print(ans)
    


# Optimized solution
n=eval(input())
n=int(n)
l=[]
for i in range(n):
    x=eval(input())
    x=int(x)
    l.append(x)
ans=max(l)
x=l.index(ans)
del l[x]
sec=max(l)
for i in range(n):
    if i==x:
        print(sec)
        continue
    print(ans)
# Original solution
N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]

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


# Optimized solution
N = int(input())
A = [int(input()) for _ in range(N)]
sorted_A = sorted(A)
[print(sorted_A[-2] if sorted_A[-1] == A[i] else sorted_A[-1]) for i in range(N)]