import numpy as np

n = int(input())
arr = np.array([int(input()) for _ in range(n)])

a_max = arr.max()

idx = np.where(arr == a_max)[0]

not_arr = arr[arr != a_max]

if len(not_arr) != 0:
    b_max = not_arr.max()

if len(idx) > 1:
    for i in range(n):
        print(a_max)
else:
    for i in range(n):
        if i in idx:
            print(b_max)
        else:
            print(a_max)
