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

A_sorted = sorted(A, reverse=True)
A_max_idx = []
A_max = A_sorted[0]
for i in range(N):
    if A_max == A[i]:
        A_max_idx.append(i)

found_semi_max = False
for i in range(N):
    if A_max != A_sorted[i]:
        A_semi_max = A_sorted[i]
        found_semi_max = True
        break

for i in range(N):
    if i in A_max_idx and found_semi_max:
        print(A_semi_max)
    else:
        print(A_max)