n = int(input())
a = [int(input()) for _ in range(n)]
m1, m2 = sorted(set(a))[n - 2:]
if a.count(m1) > 1:
    for _ in range(n):
        print(m1)
else:
    for x in a:
        print(m1) if x == m2 else print(m2)
