#include<iostream>
using namespace std;
int path[10], n, u; //记录当前路径,从下标0开始
bool st[10]; //st[i] 表示i这个数是否被使用过,使用过为true,否则为false,从1开始
void dfs(int u){ //u从0开始
if(u == n){
for(int i = 0; i < n; i++) printf("%d ", path[i]);
printf("\n");
return;
}
for(int i = 1; i <= n; i++){
if(!st[i]){
path[u] = i;
st[i] = true;
dfs(u+1); //注意这里不能写成u++,因为要恢复现场,u不能改变
st[i] = false; //恢复现场
}
}
}
int main()
{
scanf("%d", &n);
dfs(0);
}