n = input()
a = [input() for _ in xrange(n)]
m = max(a)
cnt = 0
m2 = 0
for x in a:
    if x == m:
        cnt += 1
    else:
        m2 = max(m2, x)

for x in a:
    if cnt >= 2 or x != m:
        print m
    else:
        print m2

