#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstdio>
int g[14][14];
int st[100][100];
int cnt = 0;
int n = 0;
int a = 3;
void dfs(int x, int y)
{
if (x > n) {
cnt++;
while (a) {
for (int i = 1; i <= n; i++) printf("%d ", g[0][i]);
printf("\n");
a--;
break;
}
return;
}
int flag = 0;
for (int i = 1; i <= n; i++) if (st[x][i] == 0) flag = 1;
if (flag == 0) return;
for (int i = 1; i <= n; i++) {
if (!st[x][i]) {
g[0][x] = i;
for (int j = 1; j <= n; j++) {
st[x][j]++;
st[j][i]++;
st[j][x + i - j]++;
st[j][i + j - x]++;
}
dfs(x + 1, i);
g[0][x] = 0;
for (int j = 1; j <= n; j++) {
st[x][j]--;
st[j][i]--;
st[j][x + i - j]--;
st[j][i + j - x]--;
}
}
}
}
int main()
{
scanf("%d", &n);
dfs(1, 1);
printf("%d\n", cnt);
return 0;
}