n = int(input())
a = [int(input()) for i in range(n)]
if len(set(a)) == 1:
    for i in range(n):
        print(sorted(set(a))[-1])
    exit()
x = sorted(set(a))[-1]
y = sorted(set(a))[-2]
for i in range(n):
    if a[i] != x:
        print(x)
    else:
        print(y)