#include<bits/stdc++.h>
using namespace std;
int n;
int a[15][15];
vector<int> ans;
int cnt = 0;
void attack(int x, int y, int v) {
for (int i = 1; i <= n; i++) a[x][i] += v;
for (int i = 1; i <= n; i++) a[i][y] += v;
for (int i = x, j = y; i >= 1 && j >= 1; i--, j--) a[i][j] += v;
for (int i = x, j = y; i <= n && j >= 1; i++, j--) a[i][j] += v;
for (int i = x, j = y; i <= n && j <= n; i++, j++) a[i][j] += v;
for (int i = x, j = y; i >= 1 && j <= n; i--, j++) a[i][j] += v;
a[x][y] -= (5 * v);
}
void dfs(int dep) {
if (dep > n) {
if (++cnt <= 3) {
for (int i : ans) cout << i << " ";
cout << endl;
}
return;
}
for (int i = 1; i <= n; i++) {
if (a[dep][i]) continue;
ans.push_back(i);
attack(dep, i, 1);
dfs(dep + 1);
ans.pop_back();
attack(dep, i, -1);
}
}
int main() {
cin >> n;
dfs(1);
cout << cnt;
return 0;
}