Program dfs3;
Var
panduan:array [1..50] of boolean;
h,a:array [1..50] of integer;
n,j,o:integer;
f1,f2:text;
procedure try(i:integer);
var m,p,q,k,j,l,b:integer;
begin
for k:=1 to n do begin
if panduan[k] then begin
a[i]:=k;
panduan[k]:=false;
if i=n then begin
p:=0; q:=1;
for m:=1 to (n-1) do begin
p:=p+1; q:=q+1;
h[m]:=a[p]+a[q];
end;
l:=1;
for m:=1 to (n-1) do begin
b:=2;
repeat
if h[m] mod b=0 then l:=0
else b:=b+1;
until (l=0) or (b>=h[m]/2);
end;
if l=1 then begin
for m:=1 to n do write(f2,a[m],' ');
writeln(f2);
o:=o+1;
end;
end
else try(i+1);
panduan[k]:=true;
end;
end;
end;
Begin
assign(f1,'dfs3.in');
assign(f2,'dfs3.out');
reset(f1);
rewrite(f2);
read(f1,n);
o:=0;
for j:=1 to n do
panduan[j]:=true;
try(1);
write(f2,o);
close(f1);
close(f2);
End.