n = int(input())
a_list = []
max_num = 0
sub_max = 0
all_max = False
for i in range(n):
    a = int(input())
    if sub_max < a:
        if max_num < a:
            sub_max = max_num
            max_num = a
            idx = i
        else:
            if max_num == a:
                max_num = a
                all_max = True
            else:
                sub_max = a
if all_max:
    for i in range(n):
        print(max_num)
else:
    for i in range(n):
        if i == idx:
            print(sub_max)
        else:
            print(max_num)
