N = int(input())
A = []
for n in range(N):
    a = int(input())
    A.append(a)

A_max = max(A)
C = A.count(A_max)

if C>=2:
    for l in range(N):
        print(A_max)
else:
    p = A.index(A_max)
    A = sorted(A)
    for k in range(N):
        if k==p:
            print(A[1])
        else:
            print(A_max)
