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

vector<vector<int>> fun(int pos, int n, int k, vector<int> &a) {
	if (pos == n || k == 0) {
		return {};
	}
	vector<vector<int>> ret;
	//include current element("pos") to the combinations
	auto v = fun(pos + 1, n, k - 1, a);
	for (auto c: v) {
			vector<int> cur = {a[pos]};
			//appends vector c to cur
			cur.insert(cur.end(), c.begin(), c.end());
			ret.push_back(cur);
	}
	if (k == 1) {
		ret.push_back({a[pos]});
	}
	//exclude current element("pos") from the combinations
	auto f = fun(pos + 1, n, k, a);
	//appends all vectors returned by f to the current result
	ret.insert(ret.end(), f.begin(), f.end());
	return ret;
}

int main() {
	vector<int> a = {1, 2, 3, 4, 5};
	int n = a.size(), k = 3;
	auto res = fun(0, n, k, a);
	for (auto v: res) {
		for (auto x: v) {
			cout << x << " ";
		} 
		cout << "\n";
	}
	cout << "Total number of " << k << "-combinations of " << n << "-elements set: " << res.size() << endl;
	return 0;
}