#C
from collections import Counter
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
first = sorted(set(a))[-1]
if len(a) == 1 or sorted(set(a))[0] == sorted(set(a))[-1]:
    pass
else:
    second = sorted(set(a))[-2]
for i in a:
    if i != first:
        print(first)
    else:
        print(second)
