n = int(input())
l = []
m, m2, mf = 0, 0, 0
for _ in range(n):
    x = int(input())
    if x > m: m2, m = m, x
    elif x == m: mf += 1
    elif x < m and x > m2: m2 = x
    l.append(x)
for x in l:
    if x == m: print(m if mf else m2)
    else: print(m)