N = int(input())
A = [int(input()) for i in range(N)]

sortA = sorted(A, reverse=True)

if sortA[0] == sortA[1]:
    for i in range(N):
        print(A[0])
else:
    nextP = A.index(sortA[0])
    for i in range(nextP):
        print(sortA[0])
    print(sortA[1])
    for i in range(nextP+1, N):
        print(sortA[0])