program dfs3;
Type
fxz1=array[0..100] of longint;
fxz2=array[0..50] of boolean;
var
f1,f2:text;
num1:fxz2;
sushu,num2:fxz1;
n,step,i,j,k:longint;
flag:boolean;
procedure pai(i:longint;num1:fxz2);
var
j,l:longint;
flag:boolean;
begin
for j:=1 to n do if num1[j] then begin
flag:=true;
for l:=1 to k do
if (i=1)or(num2[i-1]+j=sushu[l]) then
begin flag:=false;break;end;
if not flag then
begin num2[i]:=j;num1[j]:=false;pai(i+1,num1);end;
if i=n then begin
inc(step);for l:=1 to n do write(f2,num2[l],' ');writeln(f2);end;
for l:=1 to n do num1[l]:=true;
for l:=1 to i-1 do num1[num2[l]]:=false;
end;
end;
begin
assign(f1,'dfs3.in');
assign(f2,'dfs3.out');
reset(f1);rewrite(f2);
readln(f1,n);k:=0;step:=0;
num2[0]:=0;
for i:=0 to n do num1[i]:=true;
for i:=2 to 2*n-1 do
begin
flag:=true;
for j:=2 to trunc(sqrt(i)) do
if i mod j=0 then flag:=false;
if flag then begin inc(k);sushu[k]:=i;end;
end;
pai(1,num1);
writeln(f2,step);
close(f1);close(f2);
end.