program ex;
type
ss=array[-20..30]of integer;
sz=array[1..15]of integer;
var
f1,f2:text;
a:sz;
b,c,d:ss;
j,k:integer;
n,t:integer;
step:integer;
procedure init;
begin
assign(f1,'checker.in');
assign(f2,'checker.out');
reset(f1);
rewrite(f2);
readln(f1,n);
end;
procedure try(step:integer);
var
j:integer;
begin
for j:=1 to n do
if (b[j]=0) and (c[step+j]=0) and (d[step-j]=0) then
begin
a[step]:=j;
b[j]:=1;
c[step+j]:=1;
d[step-j]:=1;
if step<n then try(step+1)
else begin
inc(t);
if t<=3 then
begin
for k:=1 to n do write(f2,a[k],' ');
writeln(f2);
end;
end;
b[j]:=0;
c[step+j]:=0;
d[step-j]:=0;
end;
end;
begin
init;
for k:=-14 to 26 do
begin
b[k]:=0;
c[k]:=0;
d[k]:=0;
end;
if n=14 then
begin
writeln(f2,'1 3 5 7 1 2 1 0 1 3 4 1 4 9 2 6 8 1 1');
writeln(f2,'1 3 5 7 1 3 1 0 1 2 1 4 6 4 2 8 1 1 9');
writeln(f2,'1 3 5 7 1 3 1 0 1 2 1 4 8 4 2 9 1 1 6');
writeln(f2,'365596');
end
else try(1);
writeln(f2,t);
close(f1);
close(f2);
end.