n =int(input())
a =[int(input()) for _ in range(n)]
new_a=sorted(a)
first_max =new_a[-1]
second_max =new_a[-2]
for i in a:
    print(i)
    if i ==first_max:
        print(second_max)
    else:
        print(first_max)