n = int(input())
a = list(int(input()) for _ in range(n))

num = max(a)
tmp = [k for k in a if k != num]
if not tmp:
    num2 = num
else:
    num2 = max(tmp)

       

for i in range(n):
    if a[i] < num:
        print(num)
    else:
        print(num2)