n=int(input())
a=[int(input()) for i in range(n)]
b=a[:]
p=max(a)
b.remove(p)
q=max(b)

c=[i for i, x in enumerate(a) if x==p]

for i in range(n):
    if i not in c:
        print(p)
    else:
        print(q)