program checker;
var
i,n,s,q:integer;
z:longint;
a:array[1..13] of 0..1;
b:array[2..26] of 0..1;
c:array[-12..12] of 0..1;
x:array[1..13] of integer;
fin,fout:text;
procedure init;
begin
for i:=1 to 13 do
begin
a[i]:=0;
x[i]:=0;
end;
for i:=2 to 26 do b[i]:=0;
for i:=-12 to 12 do c[i]:=0;
z:=0;
end;
procedure search(i:integer);
var
j:integer;
begin
for j:=1 to n do
if (a[j]=0) and (b[i+j]=0) and (c[i-j]=0) then
begin
x[i]:=j;
a[j]:=1;
b[i+j]:=1;
c[i-j]:=1;
if i<n then search(i+1)
else
begin
inc(z);
if z<4 then
begin
for q:=1 to n do write(fout,x[q],' ');
writeln(fout);
end;
end;
a[j]:=0;
b[i+j]:=0;
c[i-j]:=0;
end;
end;
begin
assign(fin,'checker.in');
reset(fin);
assign(fout,'checker.out');
rewrite(fout);
readln(fin,n);
init;
search(1);
writeln(fout,z);
close(fin);
close(fout);
end.