{$H+}
{$APPTYPE CONSOLE}

  Const MaxS=10005;

 Type Tlist=^Plist;
      Plist=record
             v : integer;
             next : Tlist;
            End;

 Var S : String;
     N : Integer;
    level,St : Array [1..MaxS] of integer;
    root : Array [1..MaxS] of Boolean;
    A : Array [1..MaxS] of Tlist;
    ns : integer;
    maxl : Integer;
    levels : Array [1..MaxS] of Tlist;
    ans : Array [1..MaxS] of String;
    us : Array [1..MaxS] of integer;

Function Max(a,b : integer) : integer;
 Begin
  if a>b then Max:=a else max:=b;
 End;

Procedure Push(num : Integer);
 Begin
  inc(ns);
  st[ns]:=num;
 End;

Function Pop : integer;
 Begin
  pop:=st[ns];
  dec(ns);
 End;

Procedure addv;
 Begin
  inc(n);a[n]:=nil;
  push(n);
 End;

 Procedure addr(v1,v2 : integer);
   var p : Tlist;
  begin
   new(p);
   p^.v:=v2;p^.next:=a[v1];
   a[v1]:=p;
   root[v2]:=false;
  End;

Procedure addc(col : integer);
  var v,i : integer;
 Begin
  inc(n);a[n]:=nil;
  for i:=1 to col do
   begin
    v:=pop;
    addr(n,v);
   End;
  push(n);
 End;

Procedure MakeTree;
  Var i : integer;
 Begin
 for i:=1 to MaxS do root[i]:=true;
  n:=0;ns:=0;
  for i:=1 to length(s) do
    if s[i]='a' then addv else addc(ord(s[i])-ord('0'));
 End;

Procedure doneit(t : tlist);
 Begin
  if t<>nil then
   begin
    doneit(t^.next);
    dispose(t);
   End;
 End;

Procedure Done;
  Var I : integer;
 Begin
  for i:=1 to n do
   if a[i]<>nil then doneit(a[i]);
  for i:=1 to n do doneit(levels[i]);
 End;

Procedure MakeLevels(num,lvl : integer);
  var p,t : tlist;
 begin
 if lvl>maxl then maxl:=lvl;
  new(t);t^.v:=num;t^.next:=levels[lvl];levels[lvl]:=t;
  level[num]:=lvl;
  p:=a[num];
  while p<>nil do
   Begin
    MakeLevels(p^.v,lvl+1);
    p:=p^.next;
   End;
 End;

Procedure SolveVer(v : integer);
 Type temp =record
              v : integer;
              s : integer;
             End;
  Var Aa : Array [1..MaxS] of temp;
    i,nums, HS : integer;
     t : tlist;

 procedure Heapify(J: LongInt);
 var
  L, M, R: LongInt;
  T: Temp;
 begin
  M:=J;
  L:=J shl 1;
  R:=L+1;
  If (L <= HS) and (Aa[L].S < Aa[M].S) then M:=L;
  If (R <= HS) and (Aa[R].S < Aa[M].S) then M:=r;
  If M <> J then
   begin
    T:=Aa[M];
    Aa[M]:=aA[j];
    Aa[j]:=T;
    Heapify(M);
   end;
 end;

 Procedure MySort;
  var
   i: Longint;
   T: Temp;
  begin
   HS:=Nums;
   For i:=HS div 2 downto 1 do
    Heapify(i);
   While HS  > 1 do
    begin
     T:=aA[1];
     Aa[1]:=aA[HS];
     Aa[HS]:=T;
     dec(HS);
     Heapify(1);
    end;
  End;

 Begin
   t:=a[v];
   nums:=0;
   while t<>nil do
    Begin
     inc(nums);
     aa[nums].v:=t^.v;
     aa[nums].s:=us[t^.v];
     t:=t^.next;
    End;
   MySort;
   us[v]:=0;ans[v]:='';
   if nums=0 then
    begin
     us[v]:=1;
     ans[v]:='a';
     exit;
    End;
  for i:=1 to nums do
   Begin
    us[v]:=max(i+1,aa[i].s);
    ans[v]:=ans[v]+ans[aa[i].v];
   End;
  ans[v]:=ans[v]+chr(ord('0')+nums);
 End;

Procedure Solve;
  Var i : Integer;
     t : Tlist;
 Begin
  fillchar(level,sizeof(level),0);
  for i:=1 to n do levels[i]:=nil;
  for i:=1 to n do ans[i]:='a';
  maxl:=0;
  for i:=1 to n do if root[i] then MakeLevels(i,1);
  for i:=maxl downto 1 do
   Begin
    t:=levels[i];
    while t<>nil do
     Begin
      SolveVer(t^.v);
      t:=t^.next;
     End;
   End;
 End;

Procedure MyOut;
  Var i : Integer;
   myans : integer;
   sans : String;
 Begin
  myans:=0;sans:='';
  for i:=1 to n do
   if root[i] then
    Begin
    myans:=max(myans,us[i]);
    sans:=sans+ans[i];
    End;
  writeln(myans);
  writeln(sans);
 End;

begin
 Assign(input,'chandelier.in');Reset(input);
 Assign(output,'chandelier.out');Rewrite(output);
 readln(S);
 MakeTree;
 Solve;
 MyOut;
 Done;
end.
