#include <iostream>
using namespace std;
int attack[15][15], n, total = 0;
int position[15];
int dx[] = {1, -1, 0, 1};
int dy[] = {1, 1, 1, 0};
void dfs(int x, int y) {
int xx, yy, tmp[15][15];
if (x != 0 && y != 0) {
for (int j = 0; j <= 3; j++) {
for (int i = -1 * n; i < n; i++) {
xx = x + i * dx[j];
yy = y + i * dy[j];
if ((xx >= 1 && xx <= n) && (yy >= 1 && yy <= n))
attack[xx][yy] = 1;
}
}
}
if (y == n) {
total++;
if (total <= 3) {
for (int i = 1; i <= n; i++) {
cout << position[i] << " ";
}
cout << endl;
}
return;
}
for (int j = 1; j <= n; j++) {
if (!attack[j][y + 1]) {
position[y + 1] = j;
for (int a = 1; a <= n; a++) {
for (int b = 1; b <= n; b++)
tmp[a][b] = attack[a][b];
}
dfs(j, y + 1);
for (int a = 1; a <= n; a++) {
for (int b = 1; b <= n; b++)
attack[a][b] = tmp[a][b];
}
}
}
}
int main() {
cin >> n;
dfs(0, 0);
cout << total;
return 0;
}