import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())
a = [int(input()) for _ in range(n)]
a_max_1 = max(a)
a_max_2 = a_max_1
b = sorted(a, reverse=True)
for i in b:
    if i != a_max_1:
        a_max_2 = i
        break

for i in range(n):
    if a[i] == a_max_1:
        print(a_max_2)
    else:
        print(a_max_1)
