program xb;
var
a:array[1..20] of boolean;
b:array[-20..20]of boolean;
c:array[2..40] of boolean;
way:array[0..20] of integer;
f1,f2:text;
i,j:integer;
n,m:integer;
procedure nb(x:integer);
var i,j:integer;
begin
for i:=1 to n do
if a[i] and b[x-i] and c[x+i] then begin
way[x]:=i;
a[i]:=false;b[x-i]:=false;c[x+i]:=false;
if x<n then nb(x+1)
else begin m:=m+1;
if m<=3 then begin for j:=1 to n do write(f2,way[j]);
writeln(f2);end;
end;
a[i]:=true;b[x-i]:=true;c[x+i]:=true;end;
end;
begin
assign(f1,'checker.in');reset(f1);
assign(f2,'checker.out');rewrite(f2);
read(f1,n);
fillchar(a,sizeof(a),true);
fillchar(b,sizeof(b),true);
fillchar(c,sizeof(c),true);
m:=0;
nb(1);
write(f2,m);
close(f1);close(f2);
end.