n = int(input())
li = []
for i in range(n):
    li.append(int(input()))
m = max(li)
li2 = li.copy()
li2.remove(max(li2))
d = max(li2)
for i in range(n):
    if li[i] == max(li):
        print(d)
    else:
        print(m)