n = int(input())
a = []
for _ in range(0, n):
    a.append(int(input()))
b = max(a)
c = a.index(b)
a.pop(c)
e = a
d = max(e)
a.insert(c, b)
for i in range(0, n):
    if a[i] == max(a):
        print(d)
    else:
        print(b)