n = int(input())
ind = []
m = 0
k = 0
for i in range(n):
    a = int(input())
    if m == a:
        ind.append(i)
        k = a
    elif m < a:
        k, m = m, a
        ind = [i]
    elif k < a:
        k = a
print("\n".join(map(str, [k if i in ind else m for i in range(n)])))
