program dfs3(input,output);
var
a:array[1..15] of integer;
f,b:array[1..100] of boolean;
tot:longint;
n,i:integer;
procedure sushu;
var
i,j:integer;
begin
f[1]:=false;
for i:=2 to 100 do
begin
f[i]:=true;
for j:=2 to trunc(sqrt(i)) do
if i mod j=0 then f[i]:=false;
end;
end;
procedure search(step:integer);
var
i,j:integer;
begin
if step>n then
begin
for j:=1 to n do write(a[j],' ');
writeln;
inc(tot);
exit;
end;
for i:=1 to n do
if (f[i+a[step-1]]and(b[i])) or (step=1) then
begin
b[i]:=false;
a[step]:=i;
search(step+1);
a[step]:=0;
b[i]:=true;
end;
end;
begin
assign(input,'dfs3.in');
assign(output,'dfs3.out');
reset(input);
rewrite(output);
readln(n);
tot:=0;
fillchar(b,sizeof(b),true);
sushu;
search(1);
write(tot);
close(input);
close(output);
end.