https://www.luogu.com.cn/problem/P1706
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
typedef vector<long long> VI;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define pb(i) push_back(i)
#define int long long
#define INF 0x3f3f3f3f
#define oz 998244353
#define endl '\n'
#define N 15
const int mod = 1e9 + 7;
int n;
int st[N];
int q[N];
void dfs(int x) {
if (x > n) {
rep(i, 1, n)printf("%5lld", q[i]);
cout << endl;
return ;
}
rep(i, 1, n) {
if (!st[i]) {
q[x] = i;
st[i] = 1;
dfs(x + 1);
q[x] = 0;
st[i] = 0;
}
}
}
void solve() {
cin >> n;
dfs(1);
}
signed main() {
// ios::sync_with_stdio(false);
// cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while (T --)
solve();
return 0;
}