program probC;

{$APPTYPE CONSOLE}

const maxn = 10000;
var
   sa : array[1..maxn]of string;
   ba : array[1..maxn]of longint;
   tmp : array[1..9]of string;
   ch : char;
   minba, i, j, k, p, l, mink, minca : longint;
begin
   assign(input,'chandelier.in');
   reset(input);
   assign(output,'chandelier.out');
   rewrite(output);
   p := 0;
   while not seekeof do begin
      read(ch);
      if ch = 'a' then begin
         inc(p);
         sa[p]:=ch;
         ba[p]:=1;
      end else
      if ch in['1'..'9'] then  begin
          l := ord(ch)-ord('0');
          if p < l then runerror(239);
          minca := maxlongint;
         for i := p - l + 1 to p do begin
              k := i;
              minba := 0;
             for j := 0 to l - 1 do   begin
                if ba[k]+j > minba then begin
                     minba := ba[k]+j;
                end;
               if k = p then k := 1 else inc(k);
             end;
             if minba < minca then begin
                 minca := minba;
                 mink := i;
             end;
         end;
         k := mink;
        for i := 1 to  l do begin
           tmp[i] := sa[k];
           if k=p then k:=1 else inc(k);
        end;
        sa[p-l+1] := '';
        for i:= 1 to l do begin
          sa[p-l+1]:=sa[p-l+1]+tmp[i];
        end;
        p := p - l + 1;
        sa[p]:=sa[p]+ch;
        ba[p] := minca;
      end;
   end;

   writeln(ba[p]) ;
   writeln(sa[p]);

   close(input);
   close(output);
end.
 