import numpy as np
n = int(input())
a = [int(input()) for _ in range(n)]
t1 = max(a)
t1_idx = [i for i, v in enumerate(a) if v == t1]
a.sort()
try:
    t2 = a[-1*len(t1_idx)-1]
except:
    t2 = t1
for i in range(n):
    if i in t1_idx:
        print(t2)
    else:
        print(t1)
