program Razbieniya;
type 
  Razb=array [byte] of byte;
var 
 N,i,L:byte;	
 cnt: LongInt;
 X:Razb;    
procedure Next(var X:Razb;var L:byte);
var 
 i,j:byte;
 s:word;
 begin      
   i:=L-1;s:=X[L];      
   {поиск i}      
   while (i>1)and(X[i-1]<=X[i]) do 
   begin 
     s:=s+X[i];dec(i) 
   end;      
   inc(X[i]);      
   L:=i+s-1;      
   for j:=i+1 to L do X[j]:=1    
end;  

begin    
  write('N=');readln(N);
  L:=N; 
  for i:=1 to L do X[i]:=1;
  for i:=1 to L do write(X[i],' ');writeln;
  cnt:=1;
  repeat      
    Next(X,L);      
    for i:=1 to L do write(X[i],' ');writeln;    
    inc(cnt);
  until L=1;  
  writeln(cnt);
end.
