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