import sys
N = int(input())
A = [int(input()) for _ in range(N)] 
A_max1 = max(A)
if A.count(A_max1) >= 2:
    for i in range(N):
        print(A_max1)
        sys.exit()
elif  A.count(A_max1) == 1:
    A[A.index(A_max1)] = 0
    A_max2 = max(A)
    A[A.index(0)] = A_max1
    for i in range(N):
        if A[i] == A_max1:
            print(A_max2)
        else:
            print(A_max1)
