{$APPTYPE CONSOLE}
{$O-}

uses SysUtils;

type PNode = ^TNode;
     PList = ^TList;
     TNode = record
              val:integer;
              sons:PList;
             end;
     TList = record
              next,prev:PList;
              val:PNode;
             end;

var s:string;
    Stack:array[1..10000+239] of PNode;
    sp:integer;
    i,j:integer;
    pn:PNode;
    d:integer;
    se:array[1..9] of PNode;
    maxd:integer;

function isEmpty:boolean;
begin
 Result:=sp=0;
end;

procedure push(p:PNode);
begin
 inc(sp);
 Stack[sp]:=p;
 if sp>maxd then maxd:=sp;
end;

function pop:PNode;
begin
 Result:=Stack[sp];
 dec(sp);
end;

procedure insert(var P:Plist; val:PNode);
var pp,p1:PList;
begin
 new(pp);
 pp^.val:=val;
 if p=nil then
  begin
   pp^.next:=pp;
   pp^.prev:=pp;
   p:=pp;
   exit;
  end;

 pp^.next:=p;
 pp^.prev:=p^.prev;
 p1:=p^.prev;
 p^.prev:=pp;
 p1^.next:=pp;
end;

procedure dfsPrint(p:PNode);
var pl:PList;
    i:integer;
begin
 if p^.sons = nil then begin s:=s+'a'; exit; end;
 pl:=p^.sons;
 for i:=1 to p^.val do
  begin
   dfsPrint(pl^.val);
   pl:=pl^.next;
  end;

 s:=s+chr(p^.val+ord('0'));
end;

procedure dfs(var p:PNode);
var pl:PList;
    i,max:integer;
    pp:PList;
begin
 if p^.sons = nil then exit;
 max:=0;
 pl:=p^.sons;
 pp:=p^.sons;
 for i:=1 to p^.val do
  begin
   if max<pl^.val^.val then
    begin
     max:=pl^.val^.val;
     pp:=pl;
    end;
   pl:=pl^.next;
  end;

 p^.sons:=pp; 

 pl:=p^.sons;
 for i:=1 to p^.val do
  begin
   dfs(pl^.val);
   pl:=pl^.next;
  end;
end;

begin
 reset(input,'chandelier.in');
 rewrite(output,'chandelier.out');

 readln(s);
 s:=trim(s);
 sp:=0;
 maxd:=0;
 for i:=1 to length(s) do
   if s[i]='a' then
    begin
     new(pn);
     pn^.sons:=nil;
     pn^.val:=0;
     push(pn);
    end
   else
    begin
     d:=ord(s[i])-ord('0');
     new(pn);
     pn^.val:=d;
     pn^.sons:=nil;
     for j:=1 to d do
      se[j]:=pop;
     for j:=d downto 1 do
      insert(pn^.sons,se[j]);
     push(pn);
    end;

 pn:=Stack[1];
 dfs(pn);
 s:='';
 dfsPrint(pn);

 sp:=0;
 maxd:=0;
 for i:=1 to length(s) do
   if s[i]='a' then
    begin
     new(pn);
     pn^.sons:=nil;
     pn^.val:=0;
     push(pn);
    end
   else
    begin
     d:=ord(s[i])-ord('0');
     new(pn);
     pn^.val:=d;
     pn^.sons:=nil;
     for j:=1 to d do
      se[j]:=pop;
     for j:=d downto 1 do
      insert(pn^.sons,se[j]);
     push(pn);
    end;

 writeln(maxd);   
 writeln(s);
 writeln;
end.
