import numpy as np
N = int(input())
a = [int(input()) for i in range(N)]

a = np.array(a)
max_a = np.max(a)
max_idx = np.where(a == max_a)[0]
if len(max_idx) > 1:
    for i in range(N):
        print(max_a)
else:
    premax_a = np.max(np.hstack((a[0:max_idx[0]], a[max_idx[0]+1:])))
    for i in range(N):
        if i == max_idx:
            print(premax_a)
        else:
            print(max_a)