import sys
a = int(input())
a_list = []
for i in range(a):
    a_list.append(int(input()))
max_num = max(a_list)
if a_list.count(max_num) != 1:
    for i in range(a):
        print(max_num)
        sys.exit()
else:
    sec_num = sorted(a_list)[-2]
for i in a_list:
    if i == max_num:
        print(sec_num)
    else:
        print(max_num)