#include <bits/stdc++.h>
using namespace std;
const int N = 10500;
int n, a[N]; bool b[N];
int st[N], tp;
inline void dfs(int pos) {
for (int i = 1; i <= tp; ++i) if (a[i]) cout << a[i] << ' ';
puts("");
for (int i = st[tp] + 1; i <= n; ++i) {
if (b[i]) continue;
b[i] = 1;
st[++tp] = i;
a[pos] = i;
dfs(pos + 1);
st[--tp] = 0;
b[i] = 0;
}
}
signed main() {
cin >> n;
dfs(1);
return 0;
}