program dfs3;
var
i,j,n:integer;
l,p:array [1..50] of integer;
num:array [1..50,1..50] of integer;
flag:array [1..50] of boolean;
s:array [1..99] of boolean;
sum:longint;
procedure search(step:integer);
var i,t,k:integer;
begin
if step=n+1 then begin
write (p[1]);
for i:=2 to n do write (' ',p[i]);
sum:=sum+1;
writeln;
end
else begin
k:=p[step-1];
for i:=1 to l[k] do begin
t:=num[k,i];
if flag[t]=false then begin
p[step]:=t;
flag[t]:=true;
search(step+1);
flag[t]:=false;
end;
end;
end;
end;
begin
fillchar (s,sizeof(s),0);
fillchar (l,sizeof(l),0);
fillchar (num,sizeof(num),0);
for i:=1 to 99 do begin
for j:=2 to trunc(sqrt(i)) do if i mod j=0 then begin
s[i]:=true;
break;
end;
end;
assign (input,'dfs3.in');
reset (input);
readln (n);
for i:=2 to 2*n-1 do for j:=1 to n do if (i-j>0)and(s[i]=false)and(i-j<=n) then begin
inc(l[j]);
num[j,l[j]]:=i-j;
end;
close (input);
assign (output,'dfs3.out');
rewrite (output);
for i:=1 to n do begin
fillchar (flag,sizeof(flag),0);
p[1]:=i;flag[i]:=true;
search (2);
end;
writeln (sum);
close (output);
end.