n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

max1 = max(a)
max2 = sorted(a)[-2]

if a.count(max1) == 2:
    for i in range(n):
        print(max1)
elif a.count(max1) < 2:
    for i in range(n):
        if a[i] == max1:
            print(max2)
        else:
            print(max1)