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

a = np.array(a)
max_a = np.max(a)

if len(a[a<max_a]) == 0:
    premax_a = max_a
else:
    premax_a = np.max(a[a<max_a])
    
max_idxes = np.where(a == max_a)[0]

for i in range(N):
    if i in max_idxes:
        print(premax_a)
    else:
        print(max_a)
    
# for i in range(N):
#     if a[i] != max_a:
#         print(max_a)
#     else:
# #         print(i)
# #         print(a[0:i]+a[i+1:])
#         premax_a = np.max(a[0:i]+a[i+1:]) 
#         print(premax_a)