1#include<bits/stdc++.h>
2using namespace std;
3void heaps(int k, vector<int> &s, int n) {
4 if (k == 1) {
5 for (int i = 0; i < n; i++)
6 cout << s[i] << " \n"[i == n - 1];
7 return;
8 }
9 for (int i = 0; i < k - 1; ++i) {
10 heaps(k - 1, s, n);
11 if (k & 1) swap(s[i], s[k - 1]);
12 else swap(s[0], s[k - 1]);
13 }
14 heaps(k - 1, s, n);
15}
16void permutation(int n) {
17 vector<int> v(n);
18 for (int i = 0; i < n; i++) v[i] = i;
19 heaps(n, v, n);
20}
21int main() {
22 int n; cin >> n;
23 permutation(n);
24 return 0;
25}