Alice's Melting Candle Row
Alice has lined up n candles on a long shelf, numbered 1 to n from left to right; candle i has height h_i. The shelf sits right next to a radiator, and the candles behave rather strangely: a candle that stands in the shadow of a taller candle on its left gets too warm and melts. Bob, who is supposed to be keeping an eye on them, wants to know how the row will look once the melting is over.
Formally, the row changes in seconds 1, 2, 3, …. At each second, look at the current row (the candles that have not melted yet, in their original order). Every candle that is strictly shorter than the candle immediately to its left in the current row melts. All these candles melt at the same moment, judged by the row as it was at the start of the second, so a candle that melts at this second can still make its right neighbour melt at this same second. Then the melted candles disappear and the remaining candles close up, keeping their order. The leftmost candle of the current row never melts.
For each candle, Bob wants the second at which it melts, or 0 if it never melts. He also wants T, the number of the last second at which at least one candle melts (T = 0 if no candle ever melts).
Input
The first line contains an integer n (1 ≤ n ≤ 10^6), the number of candles.
The second line contains n integers h_1, h_2, …, h_n (1 ≤ h_i ≤ 10^9), the heights of the candles from left to right.
Output
On the first line print T.
On the second line print n integers separated by spaces: the i-th of them is the second at which candle i melts, or 0 if it never melts.
Notes
In the first example, at second 1 the row is 10 9 7 8 6 5 3 4 2 1 and the candles of heights 9, 7, 6, 5, 3, 2, 1 melt (each is shorter than its left neighbour, even when that neighbour melts too). The row becomes 10 8 4. At second 2 both 8 and 4 melt, leaving only 10, so T = 2.
In the second example, the row goes 5 1 3 3 2 6 → 5 3 3 6 → 5 3 6 → 5 6. A candle of the same height as its left neighbour does not melt.