// by BNU_LZM
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 30;
int a[maxn], vis[4][110], tot = 0;
void solve(int n, int *A, int cur)
{
if(cur == n)
{
for(int i = 1; i <= n; i++) printf("%d ", A[i]);
printf("\n");
tot++;
}
else
{
for(int i = 1; i <= n; i++)
{
if(vis[0][i] || vis[1][cur+1+i] || vis[2][cur+1-i+n]) continue;
else
{
A[cur+1] = i;
vis[0][i] = vis[1][cur+1+i] = vis[2][cur+1-i+n] = 1;
solve(n, A, cur+1);
vis[0][i] = vis[1][cur+1+i] = vis[2][cur+1-i+n] = 0;
}
}
}
}
int main()
{
int n = 4;
memset(vis, 0, sizeof(vis));
solve(n, a, 0);
cout << tot;
}