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