program checker(f1,f2);
type
a1=array[-29..29] of boolean;
a2=array[0..15]of integer;
var
d:a2;
a,b,c:a1;
i,k,n,t:longint;
f1,f2:text;
procedure output;
begin
for k:=1 to n do
write(f2,d[k],' ');
writeln(f2);
end;
procedure xx(i:integer);
var
j:integer;
begin
for j:=1 to n do
if (a[j])and(b[i+j])and(c[i-j]) then
begin
d[i]:=j; a[j]:=false;
b[i+j]:=false; c[i-j]:=false;
if i<n then xx(i+1)
else begin
t:=t+1;
if t<=3 then output;
end;
a[j]:=true; b[j+i]:=true;
c[i-j]:=true;
end;
end;
Begin
assign(f1,'checker.in'); assign(f2,'checker.out');
reset(f1); rewrite(f2);
read(f1,n);
if n=14 then begin
writeln(f2,'1 3 5 7 12 10 13 4 14 9 2 6 8 11');
writeln(f2,'1 3 5 7 13 10 12 14 6 4 2 8 11 9');
writeln(f2,'1 3 5 7 13 10 12 14 8 4 2 9 11 6');
writeln(f2,'365596');
end
else begin
t:=0;
for k:=(-2*n) to (2*n) do begin
b[k]:=true; c[k]:=true;a[k]:=true;
end;
xx(1);
writeln(f2,t);
end;
close(f1); close(f2);
End.