
n = int(input())
li = [0]*n
for i in range(n):
    li[i] = int(input())

max_ = max(li)
print(max_)
max_i = li.index(max_)
li.pop(max_i)
max2 = max(li)
res = [max_]*n
res[max_i] = max2

for a in res:
    print(a)
