import sys
from copy import copy

input = sys.stdin.readline
max_a = 0
big_a = 0
max_index = set()
big_index = set()
n = int(input())
for i in range(n):
    a = int(input())
    if max_a < a:
        big_index = max_index.copy()
        max_index.clear()
        max_index.add(i)
        big_a = max_a
        max_a = a
    elif max_a == a:
        max_index.add(i)
    elif big_a < a:
        big_index.clear()
        big_index.add(i)
        big_a = a
    elif big_a == a:
        big_index.add(i)
    else:
        continue

if big_a == 0:
    big_a = max_a

for i in range(n):
    if i in max_index:
        print(big_a)
    else:
        print(max_a)