a=int(input())
b=[]
for i in range(a):
    b.append(int(input()))
c=max(b)
if b.count(c)>1:
    for i in range(a):
        print(c)
else:
    d=sorted(b)
    d=d[1]
    for i in range(a):
        if i==b.index(c):
            print(d)
        else:
            print(c)