program c;

{$APPTYPE CONSOLE}

var
  Cmd: array[1..10000] of record
         Cmd: String;
         N: Integer;
  end;
  NCmd: Integer;

var
  St: array[1..10000] of Integer;
  Sp: Integer;

function CalcN(A, B, O: Integer): Integer;
var
  CurL, Max: Integer;
  I:Integer;
begin
  CurL:=0;
  Max:=0;

  I:=A + O;
  repeat
    if (St[I] = 0) then Inc(CurL)
    else if (St[I] > 0) then
     begin
       if (CurL + Cmd[St[I]].N  > Max) then Max:=CurL + Cmd[St[I]].N;
       Inc(CurL);
     end;
    Inc(I);
    if (I > B) then I:=A;
  until I = (A + O);
  if (Max < CurL) then Max:=CurL;

  CalcN:=Max;
end;

procedure Pop(Count: Integer);
var
  O, F, Min, MinO: Integer;
  T, I: Integer;
  S: String;
begin
  F:=Sp-Count+1;

  Min:=CalcN(F, Sp, 0);
  MinO:=0;

  for O:=1 to Sp-F do
    begin
      T:=CalcN(F, Sp, O);
      if (T < Min) then
        begin
          Min:=T;
          MinO:=O;
        end;
    end;

  S:='';
  I:=F + MinO;
  repeat
    if (St[I] = 0) then S:=S+'a'
    else S:=S + Cmd[St[I]].Cmd;

    I:=I+1;
    if (I > Sp) then I:=F;
  until I = F+MinO;

  S:=S + Chr(Count + Ord('0'));

  Inc(NCmd);
  Cmd[NCmd].Cmd:=S;
  Cmd[NCmd].N:=Min;
  Sp:=Sp-Count+1;
  St[Sp]:=NCmd;
end;

procedure Run;
var
  C: Char;
begin
  Sp:=0;
  while (not SeekEoln) do
    begin
      Read(C);
      if (C = 'a') then
        begin
          Inc(Sp);
          St[Sp]:=0;
        end
      else
        begin
          Pop(Ord(C) - Ord('0'));
        end;
    end;
  WriteLn(Cmd[NCmd].N);
  WriteLn(Cmd[NCmd].Cmd);
end;

begin
  Assign(Input, 'chandelier.in');
  Reset(Input);

  Assign(Output, 'chandelier.out');
  ReWrite(Output);

  Run;
end.
 