program checker;
var
f1,f2:text;
p,q,n:longint;
xx:array[1..50]of longint;
yy,l,r:array[-50..50]of boolean;
procedure start;
begin
assign(f1,'checker.in');
reset(f1);
assign(f2,'checker.out');
rewrite(f2);
read(f1,n);
p:=0;
fillchar(yy,sizeof(yy),true);
fillchar(l,sizeof(l),true);
fillchar(r,sizeof(r),true);
end;{start}
procedure print;
var
i:longint;
begin
if p<=3 then
begin
for i:=1 to n do
write(f2,xx[i],' ');
writeln(f2);
end
end;
procedure search(x:integer);
var
i:longint;
begin
for i:=1 to n do
if yy[i] and r[x+i] and l[i-x] and (xx[x]=0) then
begin
xx[x]:=i;
yy[i]:=false;
r[x+i]:=false;
l[i-x]:=false;
if x<n then
search(x+1)
else begin inc(p); print; end;
xx[x]:=0;
yy[i]:=true;
r[x+i]:=true;
l[i-x]:=true;
end;{if}
end;{search}
begin
start;
search(1);
write(f2,p);
close(f1);
close(f2);
end.