Pikule
Time limit1sMemory limit1024 MB
- Level
Not classified yet
- Solved
- No attempts yet
Statement
Pikule are round, shiny marbles that children used to play with. Every pikule in our world has one integer written on it. When a pikule with value is struck into a pikule with value , the pikule with value disappears and the struck pikule's value changes from to .
Dodo lined up pikules from left to right, numbered by position from to . At the start, the pikule at position has the number . The game goes as follows. In each step, Dodo picks one pikule at a position between and and pushes it to the left. The pikule keeps moving until it hits another pikule, and then the two merge as described above. After pushes, only the pikule at position remains.
Dodo loves big numbers. He wants to know the largest number that can remain on the last pikule, and the order in which he should push the pikules to reach it.
Input
The first line contains a natural number ().
The second line contains integers (), the numbers on the pikules.
Output
Print the number that remains on the final pikule on the first line.
On each of the next lines, print the position of the pikule Dodo pushes at step . A pikule must already be at that position when it is pushed.
Hint
First sample: Dodo can only push the second pikule. Then the first pikule's value becomes , which is the final maximum.
Second sample: There are two possible push orders. In order {2, 3}, he first pushes the pikule at position 2, leaving 2 _ 1. Then he pushes position 3, leaving a single pikule with value 1. The better order is {3, 2}. After the first push the row is 3 0 _, and after the last push the remaining pikule has value 3, which is optimal.