{$APPTYPE CONSOLE}
{$O+,Q-,R-}

uses Math, SysUtils;

type
  int = integer;
  bool = boolean;
  real = extended;
  tri = record
    dep, pos, len : int;
  end;
var
  s : string;
  r, mx, top, ulen, vpos, i, j, k, best, besti, n : int;
  u, v : array[1..20000] of char;
  st : array[0..20000] of tri;
begin
  {
  rewrite(output, 'chandelier.in');
  write('aaaaa');
  for i := 1 to 4990 do
    write('a2');
  write('5');
  exit;
  }
  reset(input, 'chandelier.in');
  rewrite(output, 'chandelier.out');
  readln(s);
  s := trim(s);
  top := 0;
  ulen := 0;
  for r := 1 to length(s) do
    if s[r] = 'a' then
    begin
      inc(ulen);
      u[ulen] := 'a';
      st[top].dep := 1;
      st[top].pos := ulen;
      st[top].len := 1;
      inc(top);
    end
    else
    begin
      n := ord(s[r]) - ord('0');
      best := 1 shl 30;
      for i := top - n to top - 1 do
      begin
        mx := 0;
        k := 0;
        for j := i to top - 1 do
        begin
          if mx < k + st[j].dep then
            mx := k + st[j].dep;
          inc(k);
        end;
        for j := top - n to i - 1 do
        begin
          if mx < k + st[j].dep then
            mx := k + st[j].dep;
          inc(k);
        end;
        if mx < k then
          mx := k;
        if best > mx then
        begin
          best := mx;
          besti := i;
        end;
      end;
      vpos := st[top - n].pos;
      for j := besti to top - 1 do
        for k := 0 to st[j].len - 1 do
        begin
          v[vpos] := u[st[j].pos + k];
          inc(vpos);
        end;
      for j := top - n to besti - 1 do
        for k := 0 to st[j].len - 1 do
        begin
          v[vpos] := u[st[j].pos + k];
          inc(vpos);
        end;
      v[vpos] := s[r];
      for k := st[top - n].pos to vpos do
        u[k] := v[k];
      inc(ulen);
      st[top - n].dep := best;
      st[top - n].len := vpos - st[top - n].pos + 1;
      dec(top, n - 1);
    end;
  assert(top = 1);
  writeln(st[0].dep);
  for i := 1 to ulen do
    write(u[i]);
  writeln;
end.
