N = int(input())
a_list = []
max_v = -1
sec = -1
max_ind = []
for i in range(N):
    a_list.append(int(input()))
    if a_list[-1]>max_v:
        max_v = a_list[-1]
        max_ind = [i]
    elif a_list[-1]<max_v:
        if a_list[-1]>sec:
            sec = a_list[-1]
    else:
        max_ind.append(i)
if len(max_ind)>1:
    for i in range(N):
        print(max_v)
else:
    for i in range(N):
        if i in max_ind:
            print(sec)
        else:
            print(max_v)