#include <iostream>
#include <vector>
#include <functional>

bool Perm(int m){
	std::function<void(int, std::vector<int>)> PermSub = [&](int n, std::vector<int> a){
		bool IsFind = false;
		if (n == m){
			std::cout << '[';
			for (auto& o : a) std::cout << o << ',';
			std::cout << ']';
			std::cout << std::endl;
		}
		else{
			for (int x = 2; x < m + 1; x++){
				IsFind = false;
				for (auto& i : a){
					if (x == i){
						IsFind = true;
						break;
					}
				}
				if (IsFind == false){
					if (n != 2 || a[0]>x){
						a.push_back(x);
						PermSub(n + 1, a);
						a.pop_back();
					}
				}
			}
		}
	};

	for (int j = 2; j < m + 1; j++) PermSub(2, { j, 1 });

	return true;
}

int main(){

	Perm(5);

	return 0;
}