P2320 [HNOI2006] Guiguzi's Money Bags

Description

Guiguzi is very clever. Because of this, he is very busy, and envoys from various feudal lords often come to consult him on current affairs. One day, while he was traveling in Xianyang, a friend told him that the largest auction house in Xianyang (Jubao Trading House) was about to hold an auction. One of the treasures caught his great interest: the Wordless Heavenly Book. However, his schedule was very tight. He had already bought a long-distance carriage ticket to Handan, and unfortunately the departure time was just as the auction would be ending. Therefore, he decided to prepare in advance: count his gold coins and seal them into small money bags, so that within the limit of his current total coins, he could pay any number of coins by selecting a combination of these sealed small bags. Guiguzi is also very frugal. He tries to minimize the number of money bags while satisfying the above requirement, and no two bags contain the same number of coins greater than $1$. Suppose he has $m$ gold coins. Can you figure out how many money bags he will use, and how many coins each bag will contain?

Input Format

Contains one integer, representing Guiguzi’s total number of gold coins $m$. Where $1 \le m \le 10^9$.

Output Format

Two lines. The first line contains an integer $h$, the number of money bags used. The second line contains the number of coins in each bag, output in increasing order and separated by spaces.

Explanation/Hint

Translated by ChatGPT 5