JOI '05 Final Round P3 - Square

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 128M

Problem type

Given n squares of the same size (n30), arrange them on an horizontal line in several columns such that the number of squares in any column should not be less than that of the column on its immediate right. For example, if n=5, then exactly seven arrangements are possible.

Any arrangement can be represented by a sequence of integers, the number of squares in the columns from left to right. For example, in case n=5, they are (5),(4,1),(3,2),(3,1,1),(2,2,1),(2,1,1,1),(1,1,1,1,1).

Your task is to write a program which, given n, outputs all possible arrangements in lexicographical order, where lexicographical order is defined as follows: (a1,a2,,as) precedes (b1,b2,,bt), if either a1>b1 or there is an integer i>1 such that a1=b1,,ai1=bi1 and ai>bi.

Input

The input consists of a single line containing n.

Output

The output should contain all the possible arrangements in lexicographical order, an arrangement a line. An arrangement (a1,,as) should be output as a sequence of integers a1,,as separated by a single space character between them.

Sample Input

Copy
5

Sample Output

Copy
5
4 1
3 2
3 1 1
2 2 1
2 1 1 1
1 1 1 1 1

Comments

There are no comments at the moment.