program ex;
type
sz=array[1..50]of integer;
var
b,c:sz;
a:array[1..4]of integer;
f1,f2:text;
flag:boolean;
i,j,n:longint;
step,t,x:longint;
procedure init;
var
i:integer;
begin
assign(f1,'dfs3.in');
assign(f2,'dfs3.out');
reset(f1);
rewrite(f2);
readln(f1,n);
for i:=1 to n do b[i]:=1;
a[1]:=2;a[2]:=3;a[3]:=5;a[4]:=7;
end;
procedure pd(c:sz);
var
i,j,num,x:integer;
begin
x:=0;num:=0;
for i:=1 to n-1 do
begin
x:=c[i]+c[i+1];
for j:=1 to 4 do
begin
if a[j]>=x then break;
if (x mod a[j]=0) then inc(num);
if num<>0 then exit;
end;
end;
inc(t);
for i:=1 to n do write(f2,c[i],' ');
writeln(f2);
end;
procedure main(step:integer);
var
i:integer;
begin
for i:=1 to n do
if b[i]>0 then
begin
c[step]:=i;
dec(b[i]);
if step<n then main(step+1)
else pd(c);
inc(b[i]);
end;
end;
begin
init;
if n=1 then writeln(f2,'0')
else begin
main(1);
writeln(f2,t);
end;
close(f1);
close(f2);
end.