N = int(input())
arr = [0] * N
for i in range(N):
    arr[i] = int(input())

sorted_list = sorted(arr)
max = sorted_list[N-1]
sub_max = sorted_list[N-2]
max_count = arr.count(max)
print(max,sub_max,max_count)

if max_count == 1:
    max_index = arr.index(max)
    for i in range(N):
        if i == max_index:
            print(sub_max)
        else:
            print(max)
else:
    for _ in range(N):
        print(max)

