n = int(input())

a = [int(input()) for i in range(n)]
a_max = max(a)
a2 = a[:]
a2.remove(a_max)
a_second_max = max(a2)

for i in range(n):
    if i == max:
        print(a_second_max)
    else:
        print(a_max)