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

for i in range(n):
    if max_a == a[i]:
        print(s_set_a)
    else:
        print(max_a)