program taskC;

{$APPTYPE CONSOLE}

uses
  SysUtils;
type
  ptrc = ^trec;
  trec = record
           kol:integer;
           A:array[1..9] of ptrc;
           ans:integer;
           max:integer;
         end;
var
maxx:integer;
St:ansiString;
stack:array[1..10000] of ptrc;
hi,len,i,j,count:integer;
cur:ptrc;

procedure build;
var zz:integer;
begin
hi:=0;
len:=length(st);
for i:=1 to len do
 begin
  if st[i]='a' then
   begin
     new(cur);
     cur^.kol:=0;
     cur^.max:=1;
     cur^.ans:=0;
     inc(hi);
     stack[hi]:=cur;
   end
  else
   begin
     count:=ord(St[i])-48;
     new(cur);
     cur^.max:=-1;
     cur^.ans:=-1;

     cur^.kol := count;zz:=count;
     for j:=hi downto hi-count+1 do
       begin
       cur^.A[{hi-j+1}zz]:=stack[j];
       dec(zz);
       stack[j]:=nil;
       end;
     hi:=hi-count+1;
     stack[hi]:=cur;
   end;
 end;
end;

function recu(var X:ptrc):integer;
var sdv:integer;
 res,maxres,tmax,aa,i:integer;
begin
 if X^.max<>-1 then
  begin
    recu:=X^.max;
    exit;
  end;
 maxres:=maxlongint;
 for sdv:=0 to X^.kol-1 do
  begin
   tmax:=0;
   for i:=0 to X^.kol-1 do
    begin
     res:=((i+sdv) mod X^.kol)+recu(X^.A[i+1]);
     if res>tmax then tmax:=res;
    end;
    if tmax<maxres then
     begin
      maxres:=Tmax;
      aa:=sdv;
     end;
  end;
 X^.ans:=aa;
 X^.max:=maxres;
 recu:=maxres;
end;

procedure process;
begin
maxx:= recu(stack[1]);
end;


procedure outs(X:ptrc);
var i,z:integer;
begin
 if X^.kol=0 then write('a')
else
begin
 for i:=1 to X^.kol do
  begin
    Z:=((i-1)+X^.ans) mod X^.kol;
    outs(X^.A[Z+1]);
  end;
 write(X^.kol); 
end;
end;

procedure outdata;
begin
 writeln(stack[1]^.max);
 outs(stack[1]);
 writeln;
end;

begin
assign(input,'chandelier.in');reset(input);
assign(output,'chandelier.out');rewrite(output);
readln(St);
build;
process;
outdata;
close(output);
close(input);
end.
