N = int(input())
A = [int(input()) for i in range(N)]
A_m = max(A)
if A.count(max) >= 2:
    for i in range(N):
        print(A_m)
else:
    for i in range(N):
        if A[i] == A_m:
            del A[i]
            A_m_new = max(A)
            print(A_m_new)
        else:
            print(A_m)
