from sys import stdin

n = int(stdin.readline())
a = [int(input()) for x in range(n)]
sort_a = sorted(a, reverse=True)
print(sort_a)

for i, ai in enumerate(a):
    max = sort_a[0]
    if max == ai:
        max = sort_a[1]

    print(max)
