program cogs640;
var
y:array[1..20] of boolean;
dx,dy:array[-19..40]of boolean;
n,i,j,ans:longint;
procedure dfs(now:integer);
var
i:integer;
begin
if now=n+1 then begin inc(ans);exit;end;
for i:=1 to n do
begin
if (y[i])and(dx[now+i])and(dy[now-i]) then begin
y[i]:=false; dx[now+i]:=false; dy[now-i]:=false;
dfs(now+1);
y[i]:=true; dx[now+i]:=true; dy[now-i]:=true; end;
end;
end;
begin
assign(input,'queen.in');reset(input);
assign(output,'queen.out');rewrite(output);
fillchar(y,sizeof(y),true);
fillchar(dx,sizeof(dx),true);
fillchar(dy,sizeof(dy),true);
readln(n);
dfs(1);
writeln(ans);
close(input);close(output);
end.