n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

b = sorted(a,reverse=True)

if b[0] == b[1]:
    for i in range(n):
        print(b[0])
else:
    s = max(a)
    for i in range(n):
        if i == a.index(s):
            print(b[1])
        else:
            print(s)