import numpy as np
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
max1 = max(A)
a = np.array(A)
index = a.argsort()[N-1:N]
A2 = sorted(set(A))
if(len(A2) == 0):
    max2 = max1
elif(len(A2) == 1):
    max2 = A2[0]
else:
    max2 = A2[1]
for i in range(N):
    if(i == index):
        print(max2)
    else:
        print(max1)
