#include <iostream>
using namespace std;
const int N = 10;
int path[N], st[N];
int n;
void dfs(int u)
{
if (u == n + 1)
{
for(int i = 1; i <= n; i ++)
printf("%d ", path[i]);
printf("\n");
return ;
}
for(int i = 1; i <= n; i ++)
{
if (!st[i])
{
st[i] = true;
path[u] = i;
dfs(u + 1);
st[i] = false;
}
}
}
int main()
{
cin >> n;
dfs(1);
return 0;
}
%%%