#include<iostream>
#include<algorithm>
using namespace std;
int n, number;
bool square[14][14];
bool isOK[14][14];
void dfs(int depth = 1)
{
if (n + 1 == depth)
{
number++;
if (number <= 3)
{
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (square[i][j])
cout << j << ' ';
cout << endl;
}
return;
}
else
for (int i = 1; i <= n; i++)
{
int j = 0;
for (j = 1; j < depth; j++)
if (square[j][i])
goto A;
for (j = max(depth - i + 1, 1); j < depth; j++)
if (square[j][j - depth + i])
goto A;
for (j = max(depth - n + i, 1); j < depth; j++)
if (square[j][-j + depth + i])
goto A;
A:
if (depth == j)
{
square[depth][i] = true;
dfs(depth + 1);
square[depth][i] = false;
}
}
}
int main()
{
cin >> n;
dfs();
cout << number;
return 0;
}