#include <iostream>
using namespace std;
bool istrue(int i, int j);
void dfs(int row,int n);
int a[14][14]= {0};
int n;
int ans = 0;
int main() {
cin >> n;
dfs(1, n);
cout << ans;
}
void dfs(int row, int n) {
if (row==n+1) {
ans++;
if (ans <= 3) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (a[i][j]== 1)cout << j << ' ';
}
}
cout << endl;
}
}
for (int j = 1; j <= n; j++) {
if (istrue(row, j)) {
a[row][j]= 1;
dfs(row+1, n);
a[row][j]= 0;
}
}
}
bool istrue(int x, int y) {
for (int i = 1; i <= x; i++) {
if (a[i][y] == 1) return false;
}
//45
for (int i = x - 1 , j = y - 1; j >= 1 && i >= 1; j--, i--) {
if (a[i][j] == 1) return false;
}
//135
for (int i = x - 1, j = y + 1; j <= n && i >= 1; j++, i--) {
if (a[i][j] == 1) return false;
}
return true;
}