N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
max1 = max(A)
index = []
for i in range(N):
    if(A[i] == max1):
        index.append(i)
A2 = sorted(set(A))
if(len(index) > 1):
    max2 = max1
else:
    max2 = A2[1]
for i in range(N):
    if(i in index):
        print(max2)
    else:
        print(max1)
