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])    
    del(r_list[index])
    m = max(r_list)
    ans = [M]*(n-1)
    ans.insert(index, m)
    for i in range(n):
        print(ans[i])