{
Written by Fyodor Menshikov 16.02.2005
}
unit lib;
interface

   function f(sum,max:integer):longint;

   procedure decode(sum:integer;code:longint);

   procedure print;

   function longrand(max:longint):longint;{0..max-1}

implementation
var
   p:array[0..121]of integer;
   len:integer;
var
   ff:array[1..121,1..121]of longint;

   procedure initff;
   var
      i,j:integer;
   begin
      for i:=1 to 121 do
         for j:=1 to 121 do
            ff[i,j]:=-1;
   end;

   function f(sum,max:integer):longint;
   begin
      if sum<1 then begin
         f:=1;
         exit;
      end;
      if max<1 then begin
         f:=0;
         exit;
      end;
      if max>sum then
         max:=sum;
      if ff[sum,max]<>-1 then begin
         f:=ff[sum,max];
         exit;
      end;
      ff[sum,max]:=f(sum,max-1)+f(sum-max,max);
      f:=ff[sum,max];
   end;

   procedure decode(sum:integer;code:longint);
   var
      i:integer;
   begin
      len:=0;
      repeat
         for i:=1 to sum+1 do begin
            if i=sum+1 then begin
               writeln('Error!');
               halt;
            end;
            if f(sum,i)>code then begin
               inc(len);
               p[len]:=i;
               code:=code-f(sum,i-1);
               sum:=sum-i;
               break;
            end;
         end;
      until sum=0;
   end;

   procedure print;
   var
      i,j,t:integer;
   begin
      for i:=len downto 2 do begin
         j:=random(i)+1;
         t:=p[i];
         p[i]:=p[j];
         p[j]:=t;
      end;
      for i:=1 to len do begin
         if i>1 then
            write('+');
         write(p[i]);
      end;
      writeln;
   end;

   function longrand(max:longint):longint;{0..max-1}
   begin
      longrand:=trunc(
         (1.0*random(256)*256*256*256+
         1.0*random(256)*256*256+
         1.0*random(256)*256+
         1.0*random(256))
         /(1.0*256*256*256*256)
         *max);
   end;

begin
   randomize;
   initff;
end.