#include<bits/stdc++.h>
using namespace std;
int n;
const int maxn = 15;
int dis[maxn][maxn] = {0};
int ans = 0;
struct Q
{
int x;
int y;
}q[maxn];
void dfs(int step)
{
if(step == n)
{
ans++;
if(ans <= 3)
{
for(int i = 0; i < n; i++)
printf("%d ", q[i].x + 1);
printf("\n");
}
return ;
}
for(int i = 0; i < n; i++)
{
if(dis[step][i] == -1)
continue;
q[step].x = i;
q[step].y = step;
for(int j = 0; j < n; j++)
{
dis[step][j] = -1;
dis[j][q[step].x] = -1;
}
for(int j = 1; j <= max(q[step].x - 1, n - q[step].x); j++)
{
if(q[step].x - j >= 0 && q[step].y - j >= 0)
dis[q[step].x - j][q[step].y - 1] = -1;
if(q[step].x + j <= n && q[step].y + j <= n)
dis[q[step].x + j][q[step]. y + j] = -1;
}
dfs(step + 1);
dis[step][q[step].x] = 0;
for(int j = 0; j < n; j++)
{
dis[step][j] = 0;
dis[j][q[step].x] = 0;
}
for(int j = 1; j <= max(q[step].x - 1, n - q[step].x); j++)
{
if(q[step].x - j >= 0 && q[step].y - j >= 0)
dis[q[step].x - j][q[step].y - 1] = 0;
if(q[step].x + j <= n && q[step].y + j <= n)
dis[q[step].x + j][q[step]. y + j] = 0;
}
}
}
int main()
{
scanf("%d", &n);
dfs(0);
printf("%d", ans);
return 0;
}