n = int(input())
a = [int(input()) for i in range(n)]
c = sorted(a,reverse=True)
if a.count(max(a))>1:
    for i in range(n):
        print(max(a))
else:
    for i in range(n):
        if i==a.index(max(a)):
            print(c[1])
        else:
            print(max(a))
    

    