n = int(input())
a_list = []
max_num = 0
sub_max = 0
all_max = False
if n == 2:
    a_list.append(int(input))
    print(a_list[1])
    print(a_list[0])
else:
    for i in range(n):
        a = int(input())
        a_list.append(a)
        if sub_max < a:
            if max_num < a:
                sub_max = max_num
                max_num = a
                idx = i
            else:
                sub_max = a
        elif max_num == a:
            max_num = a
            all_max = True
    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)
