program c;

{$APPTYPE CONSOLE}

const fname = 'chandelier';
      ifile = fname + '.in';
      ofile = fname + '.out';
      MAXN = 11000;

var s: string;
    numq,n: longint;
    q,be,ne,f: array[1..MAXN]of longint;

procedure load();
begin
  readln(s);
end;

procedure rec(x: longint);
var k,l: longint;
begin
  k:=be[x];
  l:=0;
  while k>0 do begin
    rec(k);
    k:=ne[k];
    inc(l);
  end;
  if l=0 then
    write('a')
  else
    write(l);
end;


procedure solve();
var k,l,kk,ll,min,minn,max: longint;
begin
  n:=length(s);
  for k:=1 to n do 
    if s[k]='a' then begin
      inc(numq);
      q[numq]:=k;
      f[k]:=1;
    end
    else begin
      l:=ord(s[k])-ord('0');
      min:=100000;
      dec(numq,l-1);
      for ll:=0 to l-1 do begin
        max:=0;
        for kk:=0 to l-1 do begin
          if max<f[q[numq+(ll+kk)mod l]]+kk then
            max:=f[q[numq+(ll+kk)mod l]]+kk;
        end;
        if min>max then begin
          min:=max;
          minn:=ll;
        end;
      end;
      f[k]:=min;
      for ll:=l-1 downto 0 do begin
        ne[q[numq+(ll+minn)mod l]]:=be[k];
        be[k]:=q[numq+(ll+minn)mod l];
      end;
      q[numq]:=k;
    end;
  writeln(f[q[1]]);
  rec(q[1]);
end;

procedure save();
begin

end;

begin
  assign(input,ifile);
  reset(input);
  assign(output,ofile);
  rewrite(output);
  load;
  solve;
  save;
end.
 