n = int(input())
a = []
num = []
prem = 0
m = 0
j = 0
for i in range(n):
    a.append(int(input()))
for i in range(n):
    if a[i] > m:
        prem = m
        m = a[i]
        num = []
        num.append(i)
    if a[i] == m:
        num.append(i)
    elif a[i] > prem:
        prem = a[i]
print(num,m,prem)
for i in range(n):
    if j < len(num) and i == num[j]:
        print(prem)
        j += 1
    else:
        print(m)
