n = int(input())
a = [int(input()) for i in range(n)]
a_first = sorted(a)[-1]
a_second = sorted(a)[-2]
if a_first == a_second:
    for i in range(n):
        print(a_first)
else:
    for i in range(n):
        if i == a.index(a_first):
            print(a_second)
        else:
            print(a_first)