program dfs3;
var
a:array[1..1000] of integer;
b:array[1..1000] of boolean;
n,q,i,c:integer;
s:longint;
fin,fout:text;
procedure init;
begin
for i:=1 to n do
begin
a[i]:=0;
b[i]:=true;
end;
end;
procedure print;
begin
inc(s);
for i:=1 to n do write(fout,a[i],' ');
writeln(fout);
end;
function sushu(kk:integer):boolean;
begin
sushu:=true;
for i:=2 to trunc(sqrt(kk)) do
if kk mod i=0 then
begin
sushu:=false;
exit;
end;
end;
procedure search(t:integer);
var
k:integer;
begin
k:=0;
repeat
inc(k);
if b[k] and sushu(k+a[t-1]) then
begin
a[t]:=k;
b[k]:=false;
if t=n then print
else search(t+1);
b[k]:=true;
a[t]:=0;
end;
until k=n;
end;
begin
assign(fin,'dfs3.in');
reset(fin);
assign(fout,'dfs3.out');
rewrite(fout);
readln(fin,n);
init;
s:=0;
for q:=1 to n do
begin
a[1]:=q;
b[q]:=false;
search(2);
b[q]:=true;
end;
writeln(fout,s);
close(fin);
close(fout);
end.