n = int(input())
a = [int(input()) for _ in range(n)]

if a.count(max(a)) >= 2:
    for _ in range(n):
        print(max(a))
else:
    for _ in range(n):
        if a[_] == max(a):
            print(sorted(a)[-2])
        else:
            print(max(a))
