Listing Square Arrangements in Lexicographic Order

No attempts yetTime limit1sMemory limit128 MB

Problem

There are $n$ squares of the same size. Arrange them into several columns with their bottom edges aligned horizontally. Adjacent columns must be placed so that the left column is never lower than the right column (that is, the heights are non-increasing from left to right). For example, when $n = 5$ there are the following 7 possible arrangements.

Each arrangement is represented by the sequence of the number of squares stacked in each column, read from left to right. For instance, when $n = 5$ the 7 arrangements above are written as

$$(5)\quad (4, 1)\quad (3, 2)\quad (3, 1, 1)\quad (2, 2, 1)\quad (2, 1, 1, 1)\quad (1, 1, 1, 1, 1)$$

Given $n$, write a program that outputs every possible arrangement in lexicographic order. Here $n \le 30$. Lexicographic order is defined as follows: for two arrangements $(a_1, a_2, \ldots, a_s)$ and $(b_1, b_2, \ldots, b_t)$, arrangement $(a_1, a_2, \ldots, a_s)$ is printed before $(b_1, b_2, \ldots, b_t)$ when $a_1 > b_1$, or when there exists an integer $i > 1$ such that $a_1 = b_1, \ldots, a_{i-1} = b_{i-1}$ and $a_i > b_i$.

Input

The first line contains the integer $n$.

Output

Print every arrangement in lexicographic order, one per line, followed by a trailing newline. An arrangement $(a_1, a_2, \ldots, a_s)$ is printed as the integers $a_1, a_2, \ldots, a_s$ in this order, separated by single spaces.