#include <iostream>
#include <cstring>
using namespace std;
const int N = 10;
int path[N];
bool state[N];
int n;
void DFS(int x)
{
if(x>n)//结束条件:遍历到最后一位了
{
for (int i = 1; i <= n; i++)
{
cout << path[i] << " ";
}
cout << endl;
}
for (int i = 1; i <= n; i++)
{
if (!state[i])//如果没被访问则进行存储
{
path[x] = i;
state[i] = true;
DFS(x + 1);//访问下一个节点
state[i] = false;//恢复访问状态
}
}
}
int main()
{
cin >> n;
DFS(1);//遍历点
return 0;
}