program checker(input,output);
var
a:array[1..14]of integer;
s:longint;
n:integer;
procedure print;
var i:integer;
begin
for i:=1 to n do write(output,a[i],' ');
writeln(output);
end;
procedure search(t:integer);
var i,j:integer;b:boolean;
begin
for i:=1 to n do
begin
b:=false;
for j:=1 to t-1 do
if(i=a[j])or(abs(t-j)=abs(i-a[j]))then b:=true;
if not b then begin
a[t]:=i;
if t<n then search(t+1)
else begin
if s<3 then print;
s:=s+1;
end;
end;
end;
end;
begin
assign(input,'checker.in');assign(output,'checker.out');
reset(input);rewrite(output);
read(input,n);
if n<12 then begin
s:=0;
search(1);
write(output,s);
end;
close(input);close(output);
end.