program EmberAsh;
var
a:array[0..15]of integer;
n,i,j,k,ss,max,head:longint;
t:array[1..15]of boolean;
sushu:array[1..30]of boolean;
tt:array[1..15]of boolean;
procedure try(o:integer);
label 1;
var
i,j,k:longint;
begin
if o=n+1 then
begin
for i:=1 to n-1 do
write(a[i],' ');
writeln(a[n]);
inc(ss);
end
else
begin
for i:=1 to n do
begin
if (t[i]=false)and(not((n mod 2=1)and(o=1)and(i mod 2=0))) then
if (sushu[i+a[o-1]]=true)or(a[o-1]=0) then
begin
inc(head);
a[head]:=i;
t[i]:=true;
try(o+1);
t[i]:=false;
a[head]:=0;
dec(head);
end;
end;
end;
end;
BEGIN
assign(input,'dfs3.in');reset(input);
assign(output,'dfs3.out');rewrite(output);
readln(n);
sushu[1]:=true;
sushu[2]:=true;
sushu[3]:=true;
sushu[5]:=true;
sushu[7]:=true;
sushu[11]:=true;
sushu[13]:=true;
sushu[17]:=true;
sushu[19]:=true;
sushu[23]:=true;
sushu[29]:=true;
tt[1]:=false;
tt[3]:=false;
tt[5]:=false;
tt[7]:=false;
tt[9]:=false;
tt[11]:=false;
tt[13]:=false;
tt[15]:=false;
try(1);
writeln(ss);
close(input);close(output);
END.