#include <stdio.h> #include <string.h> #define M 12 int map[M][M],n,sum; int ini[M]; int jud(int row,int col) { for(int i=1;i<row;i++) for(int j=1;j<=n;j++) if(map[i][j] && (row==i || col==j || i+j==row+col || i-j==row-col)) return 0; return 1; } void dfs(int row) { if(row>n) { sum++; return ; } for(int i=1;i<=n;i++) { map[row][i]=1; if(jud(row,i)) dfs(row+1); map[row][i]=0; } } int main(int argc, char *argv[]) { #ifdef __LOCAL freopen("in.txt","r",stdin); #endif memset(ini,0,sizeof(ini)); while(scanf("%d",&n) && n) { if(ini[n]) { printf("%d\n",ini[n]); continue; } sum=0; memset(map,0,sizeof(map)); dfs(1); ini[n]=sum; printf("%d\n",sum); } return 0; }