n = int(input())
r_list = []
for i in range(n):
    r_list.append(int(input()))

M = max(r_list)
max_index = [i for i, v in enumerate(r_list) if v == max(r_list)]

if len(max_index) > 1:
    for i in range(n):
        print(M)
if len(max_index) == 1:
    index = int(max_index[0])
    
    for i in range(index):
        print(M)
        
    del(r_list[index])
    print(max(r_list))
    
    for i in range(n-index-1):
        print(M)