N = int(input())
A = [int(input()) for i in range(N)]
B = max(A)
C = A.count(B)
if C==1:
    for i in range(N):
        if A[i]!=B:
            print(B)
        else:
            print(sorted(A)[1])
else:
    for i in range(N):
        print(B)