Cafeteria Queue
Time limit2sMemory limit1024 MB
Given n, find the maximum number of expansion stages k and the per-stage push counts a_i that grow a two-student line to exactly n students.
- Level
Medium6 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Statement
Innokentiy, the chief steward of the cafeteria at the Galactic School of Goodness, loves order. Yet every day during the very long break, when students head to lunch, chaos takes over his domain.
It starts innocently: the two fastest students stand in line. Then the line grows in stages. In stage (), people push into every gap between neighboring students already in line. For example, with , , , the line has 5 people after the first stage and 9 after the second.
Innokentiy wants to bring this under control. He knows only the final number of students in the line, and he wants to find out how the line expanded. Since does not determine the process uniquely, he wants the maximum possible number of stages and a matching sequence (), giving the number of people who pushed into each gap at each stage.
Input
A single integer is given (), the final number of students in the line.
Output
On the first line, print the maximum number of stages . On the second line, print positive integers separated by spaces. If several sequences of maximum length exist, print any one of them.
Hint
In the first example, there is only one possibility: two people push in during the first stage. In the second example, the process is not determined uniquely. One scenario with is given in the statement, but the maximum number of stages is 3.