#include <iostream>

using namespace std;

int n, stack[100];

int getMax(int level) {
	int max = 0;
	for(int i = 1; i <= level-1;++i) {
		if(stack[i]>max) {
			max = stack[i];
		}
	}	
	return max;
}

void partition(int level) {
     if(level == n + 1) {
     	 for(int i = 1; i <= level-1;++i) {
           cout<<stack[i]<<" ";
         }
         cout<<endl;
     } else {
         stack[level] = 0;
         while(stack[level]<getMax(level)+1) {
               stack[level] += 1;
               partition(level+1);
         }
     }
}

int main(int argc, char const *argv[]) {

  n = 5;
  partition(1);

  return 0;
}
