#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> nums;
int main() {
int n;
cin >> n;
for(int i = 1; i <= n; i ++)
nums.push_back(i);//注意next_permutation排序的序列开始需要顺序排列
do {
for (int num : nums) {
cout << num << " ";
}
cout << endl;
} while (next_permutation(nums.begin(), nums.end()));//next_permutation返回一个布尔值判断是否输出原排列并返回新排列
return 0;
}