#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>

using namespace std;

void p(const int& m, const int& n, int d)
{
	static vector<int> buf;

	if (n == d) {
		copy(buf.begin(), buf.end(), ostream_iterator<int>(cout, " "));
		cout << endl;
	} else {
		for (int i = 1; i <= m; i++) {
			if (find(buf.begin(), buf.end(), i) == buf.end()) {
				buf.push_back(i);
				p(m, n, d + 1);
				buf.pop_back();
			}
		}
	}
}

void c(const int& m, const int& n, int d)
{
	static vector<int> buf;

	if (n == d) {
		copy(buf.begin(), buf.end(), ostream_iterator<int>(cout, " "));
		cout << endl;
	} else {
		for (int i = 1; i <= m; i++) {
			if (buf.empty() || buf.back() < i) {
				buf.push_back(i);
				c(m, n, d + 1);
				buf.pop_back();
			}
		}
	}
}

int main()
{
	int m, n;

	cout << "Please input m: ";
	cin >> m;
	cout << "Please input n: ";
	cin >> n;

	cout << "--- P(m, n) ---" << endl;
	p(m, n, 0);

	cout << "--- C(m, n) ---" << endl;
	c(m, n, 0);

	return 0;
}

