Exile_Code @ 2023-11-01 12:58:54
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <list>
#include <string>
#include <cmath>
#include <bitset>
#include <stack>
#include <unordered_set>
#define ull unsigned long long
#define ll long long
#define pii pair<ll ,ll>
#define x first
#define y second
#define cy cout<<"Yes"<<endl
#define cn cout<<"No"<<endl
#define forn(i,n) for(int (i)=0;(i)<(n);(i)++)
#define forne(i,n) for(int (i)=1;(i)<=(n);(i)++)
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 5;
ll t;
int n;
map<int, int>mp;
map<int, int>mp2;
vector<int>row;
set<string>rs;
void dfs(int th, string s) {
if (th > n) {
rs.insert(s);
return;
}
forne(i, n) {
if (mp[th-i]&&mp2[th+i]&&row[i]==0) {
s += to_string(i);
s += " ";
mp[th - i] = 0; mp2[th + i] = 0;
row[i] = 1;
dfs(th + 1, s);
mp[th - i] = 1; mp2[th + i] = 1;
row[i] = 0;
s.pop_back();
s.pop_back();
}
}
}
void solve() {
mp.clear();
row.clear();
cin >> n;
row.resize(n+1);
for (int i = 0; i < n; i++) {
mp[i]++; mp[-i]++;
}
forne(i, 2 * n)
mp2[i]++;
forne(i, n) {
string a = to_string(i);
a += " ";
mp[1 - i] = 0; mp2[1 + i] = 0;
row[i] = 1;
dfs(2, a);
mp[1 - i] = 1; mp2[1 + i] = 1;
row[i] = 0;
}
int i = 0;
for (auto a : rs) {
if (i++ == 3)
break;
cout << a << endl;
}
cout << rs.size() << endl;
}
int main() {
//cin >> t;
t = 1;
while (t--)
solve();
return 0;
}