#include <iostream>
#include <vector>
#include <functional>
using namespace std;

int main() {
	for (int n = 1; n <= 10; ++n) {	
		long long p = 1;
		int s = 0;
		for (int i = 1; i <= n; ++i) {
			s += i;
			p *= i;
		}
		vector<int> way;
		function<void (int, int, int,int)> rec = [&](int step, int prev, int as, long long ap) {
			if (p % ap != 0) return;
			if (step == n) {
				if (as == s && ap == p) {
					for (int num : way) {
						cout << num << ' '; 	
					} 
					cout << endl;
				}
				return; 
			}
			if (as + prev > s) return;
			for (int next = prev; next <= n; ++next) {
				way.push_back(next);
				rec(step+1, next, as + next, ap * next);
				way.pop_back();
			}
		};
		cout << "n = " << n << endl;
		rec(0, 1, 0, 1);
		cout << endl;
	}
	return 0;
}