{$APPTYPE CONSOLE}
uses math;
const maxn=10002;
      maxnp=12;
      maxnum=1000000000;
var s:string;
    n,nst:longint;
    p:array[1..maxn,1..maxnp] of longint;
    way,r,np,st:array[1..maxn] of longint;

procedure readdata;
begin
 readln(s);
end;

procedure rec(i:longint);
var s,c,j:longint;
begin
 if np[i]=0 then
  begin
   r[i]:=1;
   exit;
  end;
 for j:=1 to np[i] do
 rec(p[i,j]);
 r[i]:=maxnum;
 for c:=1 to np[i] do
 begin
  s:=0;
  for j:=1 to np[i] do
  s:=max(s,r[p[i,(j+c+np[i]-1) mod np[i]+1]]+j-1);
  if s<r[i] then
   begin
    r[i]:=s;
    way[i]:=c;
   end;
 end;
end;

procedure solve;
var i,j:longint;
begin
 n:=0;
 nst:=0;
 for i:=1 to length(s) do
 begin
  n:=n+1;
  if s[i]='a' then
   begin
    nst:=nst+1;
    st[nst]:=n;
   end
  else if s[i] in ['1'..'9'] then
   begin
    np[n]:=ord(s[i])-ord('0');
    for j:=1 to np[n] do
    p[n,np[n]-j+1]:=st[nst-j+1];
    nst:=nst-np[n]+1;
    st[nst]:=n;
   end;
 end;
 rec(st[nst]);
end;

procedure outrec(i:longint);
var j:longint;
begin
 if np[i]=0 then
  begin
   write('a');
   exit;
  end;
 for j:=1 to np[i] do
 outrec(p[i,(j+way[i]+np[i]-1) mod np[i]+1]);
 write(np[i]);
end;

procedure outdata;
begin
 writeln(r[st[nst]]);
 outrec(st[nst]);
end;

begin
 assign(input,'chandelier.in');
 reset(input);
 assign(output,'chandelier.out');
 rewrite(output);
 readdata;
 solve;
 outdata;
 close(output);
end.
