N = int(input())
A = [int(input()) for i in range(N)]
max = max(A)
if A.count(max) >=2:
    for i in range(N):
        print(max)
else:
    M = A.index(max)
    for i in range(M):
        print(max)
    print(max(A.remove(max)))
    for i in range(M+1,N):
        print(max)