#include <iostream>
void print( unsigned int n, const unsigned int A[] )
{
for( unsigned int i = 0 ; i <= n ; ++i ) std::cout << A[i] << ' ' ;
std::cout << '\n' ;
}
void print_partitions( unsigned int n, unsigned int A[], unsigned int j = 0 )
{
if( n > 0 )
{
A[j] = n ;
print( j, A ) ;
for( unsigned int i = j ? A[j-1] : 1 ; i <= n/2 ; ++i )
{
A[j] = i ;
print_partitions( n-i, A, j+1 ) ;
}
}
}
int main()
{
constexpr unsigned int N = 6 ;
unsigned int A[N] ;
print_partitions( N, A );
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdm9pZCBwcmludCggdW5zaWduZWQgaW50IG4sIGNvbnN0IHVuc2lnbmVkIGludCBBW10gKQp7CiAgICBmb3IoIHVuc2lnbmVkIGludCBpID0gMCA7IGkgPD0gbiA7ICsraSApIHN0ZDo6Y291dCA8PCBBW2ldIDw8ICcgJyA7CiAgICBzdGQ6OmNvdXQgPDwgJ1xuJyA7Cn0KCnZvaWQgcHJpbnRfcGFydGl0aW9ucyggdW5zaWduZWQgaW50IG4sIHVuc2lnbmVkIGludCBBW10sIHVuc2lnbmVkIGludCBqID0gMCApCnsKICAgIGlmKCBuID4gMCApCiAgICB7CiAgICAgICAgQVtqXSA9IG4gOwogICAgICAgIHByaW50KCBqLCBBICkgOwogICAgICAgIGZvciggdW5zaWduZWQgaW50IGkgPSBqID8gQVtqLTFdIDogMSA7IGkgPD0gbi8yIDsgKytpICkKICAgICAgICB7CiAgICAgICAgICAgIEFbal0gPSBpIDsKICAgICAgICAgICAgcHJpbnRfcGFydGl0aW9ucyggbi1pLCBBLCBqKzEgKSA7CiAgICAgICAgfQogICAgfQp9CgppbnQgbWFpbigpCnsKICAgIGNvbnN0ZXhwciB1bnNpZ25lZCBpbnQgTiA9IDYgOwogICAgdW5zaWduZWQgaW50IEFbTl0gOwogICAgcHJpbnRfcGFydGl0aW9ucyggTiwgQSApOwp9Cg==