n = int(input())
l = []
for i in range(n):
    l.append(int(input()))
m = max(l)
ans = [m]*n
if len(set(l)) == 1:
    for i in ans:
        print(i)
else:
    x = sorted(set(l))[-2]
    a = [index for index, value in enumerate(l) if value == m]
    for i in a:
        ans[i] = x
    for i in ans:
        print(i)
