Walking Robot
A renowned robotics company has developed a new model: a bipedal walking robot. For testing purposes, several columns, each composed of identical cubes, are arranged in a row. The robot can step from one column to the next only if the difference in their heights (i.e., the number of cubes) is no more than 1.
Your task is to determine the minimum number of cubes that must be removed so that the robot can traverse the entire row of columns from start to finish.
Input
The first line of the input contains an integer N (1 ≤ N ≤ 10^6), representing the number of columns. The second line contains N non-negative integers, each not exceeding 2·10^6, which specify the heights of the columns.
Output
On the first line of the output, print the minimum number of cubes that need to be removed. On the second line, print N numbers, each representing the number of cubes remaining in the corresponding column.