n = int(input())
a = [int(input()) for _ in range(n)]
max_a = max(a)
set_a = set(a)
s_set_a = sorted(set(a))[-2]
for i in range(n):
    if max_a == a[i]:
        if len(set_a) == 1:
            print(max_a)
        else:
            print(s_set_a)
    else:
        print(max_a)