//next_permutation的方法
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
constexpr int N = 1e6 + 10, inf = 0x3f3f3f3f;
int a[N]; // 表示选择与不选
int n;
void solve()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
a[i] = i;
}
do
{
for (int i = 1; i <= n; i++)
{
cout << a[i] << ' ';
}
cout << endl;
} while (next_permutation(a + 1, a + n + 1));
}
signed main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T = 1;
while (T--)
{
solve();
}
return 0;
}
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
constexpr int N = 1e6 + 10, inf = 0x3f3f3f3f;
int a[N]; // 表示选择与不选
int n;
bool vis[N];
void dfs(int u)
{
if (u == n + 1)
{
for (int i = 1; i <= n; i++)
{
cout << a[i] << ' ';
}
cout << endl;
}
for (int i = 1; i <= n; i++)
{
if (!vis[i])
{
vis[i] = true;
a[u] = i;
dfs(u + 1);
vis[i] = false;
}
}
}
void solve()
{
cin >> n;
dfs(1);
}
signed main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T = 1;
while (T--)
{
solve();
}
return 0;
}