from collections import Counter

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

c = Counter(A)

mx = max(A)
B = list(set(A))
B.remove(mx)
bmx = max(B)
for i in range(N):
    if A[i] != mx:
        print(mx)
    elif c[mx] == 1:
        print(bmx)
    else:
        print(mx)