program dfs3;
var
n,i,j,ans:longint;
hx,hx2:array[1..29]of boolean;
sz:Array[1..15]of longint;
procedure find(c:longint);
var
i:longint;
begin
if c>n then begin
for j:=1 to n do
write(sz[j],' ');
writeln;
ans:=ans+1;
end
else begin
for i:=1 to n do
begin
if c=1 then begin
sz[c]:=i;
hx2[i]:=false;
find(c+1);
hx2[i]:=true;
end
else begin
if (hx2[i])and(hx[i+sz[c-1]]) then begin
sz[c]:=i;
hx2[i]:=false;
find(c+1);
hx2[i]:=true;
end;
end;
end;
end;
end;
begin
assign(input,'dfs3.in');
assign(output,'dfs3.out');
reset(input);
rewrite(output);
readln(n);
fillchar(hx,sizeof(hx),true);
for i:=4 to 29 do
for j:=2 to i-1 do
if i mod j=0 then hx[i]:=false;
ans:=0;
fillchar(hx2,sizeof(hx2),' ');
find(1);
writeln(ans);
close(input);
close(output);
end.