var
flag1:array[1..13] of boolean;
flag2:array[2..26] of boolean;
flag3:array[-12..12] of boolean;
a:array[1..13] of integer;
n:integer;
c:longint;
f1,f2:text;
procedure ini;
begin
assign(f1,'checker.in');reset(f1);
assign(f2,'checker.out');rewrite(f2);
readln(f1,n);
fillchar(flag1,sizeof(flag1),true);
fillchar(flag2,sizeof(flag2),true);
fillchar(flag3,sizeof(flag3),true);
fillchar(a,sizeof(a),0);
end;
procedure print;
var
j:integer;
begin
for j:=1 to n do write(f2,a[j]);
writeln(f2);
end;
procedure try(i:integer);
var
k:integer;
begin
for k:=1 to n do begin
if flag1[k] and flag2[i+k] and flag3[i-k]
then begin
a[i]:=k;flag1[k]:=false;flag2[i+k]:=false;flag3[i-k]:=false;
if i=n then begin
inc(c);if c<=3 then print;
end
else try(i+1);
flag1[k]:=true;flag2[i+k]:=true;flag3[i-k]:=true;
end;
end;
end;
begin
ini;
try(1);
writeln(f2,c);
close(f2);close(f1);
end.