{
task: scales
lang: pascal
}
program scales;
const len = 200;
var deg : array [0 .. 250 ]of record
                               l :integer;
                               m : array [0.. 290 ] of integer;

                         end;
   mas,m1,m2 : array [  0 .. 290 ] of integer;
   used,u1, u2 : array [ 0 ..290 ] of integer;
   st:string;
   ch:char;
   t,mintis,poz,
   i,j,x,max,n,ml:integer;
   f:text;
procedure make_d;
var i,j,mintis :integer;
 begin
 deg [ 0 ]. l := 1;
 deg [ 0 ]. m [ len] :=1;
  for i := 1 to 220 do
   begin
    mintis:= 0;
    for j := len downto len - deg[i-1].l+1 do
       begin
        deg [ i ]. m [ j ] := (deg [i-1].m[j]*3+mintis ) mod 10;
        mintis := (deg [i-1].m[j]*3+mintis ) div 10;
       end;
     deg [ i].l := deg[i-1].l;
    if mintis <> 0 then
    begin
    inc ( deg[i]. l );
    deg [ i].m [len-deg[i].l+1]:=mintis;
    end;
  end;
 end;
function findi: integer;
var i,j:integer;
 bad : boolean;
 begin
  for i := 0 to 220 do
   if deg [i].l >ml then break;
   dec (i);
   while  deg[i].l = ml do
   begin
    bad:=false;
     for j :=len- deg[i].l+1 to len do
     if m1 [j] <deg[i].m[j] then
      begin
       dec (i);
       bad:=true;
       break;
      end
      else if m1[j]> deg[i].m[j] then break;
      if not ( bad ) then break;
    end;
   findi := i;
end;
procedure minus ( x:integer );
var i,yra,mintis:integer;
 begin
  mintis:=0;
  yra:=len+1;
   for i := len downto len-ml+1 do
    begin
    if m1 [ i ] < mintis +deg[x].m[i] then
     begin
      m2 [ i ] :=(10+m1[i]-mintis -deg[x].m[i]) mod 10;
      mintis:=1;
      yra:=i;
     end
     else
     begin
      m2 [ i ] :=m1[i]-mintis -deg[x].m[i];
      mintis:=0;
       if m2[i] <>0 then yra:=i;
     end;
    end;
  m1 :=m2;
  ml:=len -yra+1;
 end;
procedure spausd ( x : integer );
var i:integer;
begin
 for i := len-deg[x].l+1 to len do
  write ( f, deg[x].m[i]);
  write (f, ' ');
end;
 begin
  make_d;
  assign ( f, 'scales.in');
  reset ( f );  {scales.out}
  n:=0;
  while not (eoln ( f )) do
   begin
    inc (n );
    read (f,ch);
    st:=ch;
    val (st,mas[n],poz);
    end;
  close ( f );
  for j := n downto 1 do
    m1 [ len-(n-j)] := mas[j];
    ml := n;
  while ml <> 0 do
   begin

    x:=findi;
    minus( x);
    inc (used[ x]);
    if x > max then max:=x;
   end;
  mintis:=0;
  i:=0;
  while i <= max do
   begin
     t := used[i]+ mintis;
     if t = 0 then
     begin
     u1 [ i ] :=0;
     u2 [i]:=0;
     mintis:=0;
     end
     else
     if t = 1 then
     begin
      u1 [ i ] :=1;
      u2[i]:=0;
      mintis:=0;
     end
     else
     if t = 2 then
     begin
      u1[i]:=0;
      u2[i]:=1;
      mintis:=1;
     end
     else
     if t= 3 then
     begin
       u1[i]:=0;
       u2[i]:=0;
       mintis:=1;
     end;
     if (i = max ) and (mintis <> 0) then inc ( max );
     inc ( i );

   end;

  assign (f, 'scales.out');
  rewrite (f );
  x:=0;
  for i := 0 to max do
  if u2[i] <> 0 then inc (x );
  write ( f, x, ' ' );
  for i := 0 to max do
  if u2 [ i] <> 0 then spausd (i);
  writeln ( f );
  x:=0;
  for i := 0 to max do
  if u1[i] <> 0 then inc (x );
  write ( f, x, ' ' );
  for i := 0 to max do
  if u1 [ i] <> 0 then spausd (i);
  close ( f );
 end.
