from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(stdin.readline().rstrip()) for _ in range(n)]

m1 = [x for i, x in enumerate(a) if x == max(a)]

for i in a:
    if len(m1) > 1:
        print(max(m1))
    else:
        m2 = max([x for x in a if x != max(m1)])
        print(max(m1) if a != max(m1) else m2)
