#include <iostream>
using namespace std;
int n, sum, stack[10];
void solve(int level) {
if(sum == n) {
for(int i = 1; i < level; ++i) {
cout<<stack[i]<<" ";
}
cout<<endl;
} else {
if (level == 1) stack[level] = 0; else stack[level] = stack[level-1]-1;
while(stack[level] + sum < n) {
stack[level]+=1;
sum += stack[level];
solve(level+1);
sum -= stack[level];
}
}
}
int main(int argc, char const *argv[]) {
sum = 0;
n = 5;
solve(1);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBuLCBzdW0sIHN0YWNrWzEwXTsKCnZvaWQgc29sdmUoaW50IGxldmVsKSB7CiAgICAgaWYoc3VtID09IG4pIHsKICAgICAgIGZvcihpbnQgaSA9IDE7IGkgPCBsZXZlbDsgKytpKSB7CiAgICAgICAgIGNvdXQ8PHN0YWNrW2ldPDwiICI7CiAgICAgICB9CiAgICAgICBjb3V0PDxlbmRsOwogICAgIH0gZWxzZSB7CiAgICAgICAgaWYgKGxldmVsID09IDEpIHN0YWNrW2xldmVsXSA9IDA7IGVsc2Ugc3RhY2tbbGV2ZWxdID0gc3RhY2tbbGV2ZWwtMV0tMTsKICAgICAgICB3aGlsZShzdGFja1tsZXZlbF0gKyBzdW0gPCBuKSB7CiAgICAgICAgICAgICAgc3RhY2tbbGV2ZWxdKz0xOwogICAgICAgICAgICAgIHN1bSArPSBzdGFja1tsZXZlbF07CiAgICAgICAgICAgICAgc29sdmUobGV2ZWwrMSk7CiAgICAgICAgICAgICAgc3VtIC09IHN0YWNrW2xldmVsXTsKICAgICAgICB9CiAgICAgfQoKfQppbnQgbWFpbihpbnQgYXJnYywgY2hhciBjb25zdCAqYXJndltdKSB7CgogIHN1bSA9IDA7CiAgbiA9IDU7CiAgc29sdmUoMSk7CiAgcmV0dXJuIDA7Cn0K