n = int(input())
suretsu0 = []

biggest_num = 0
secondly_biggest_num=0
for i in range(n):
    a = int(input())
    suretsu0.append(a)

suretsu = [x for x in suretsu0]
suretsu.sort()


biggest_num = suretsu[-1]
secondly_biggest_num=suretsu[-2]

print(secondly_biggest_num,biggest_num)


for ele in suretsu0:
    if ele==biggest_num:
        print(secondly_biggest_num)
    else:
        print(biggest_num)   
