{$I-,S-,Q-,R-,D-,L-,Y-,P-}
{$APPTYPE CONSOLE}
const maxn=5*10000;
      inf=1000000000;
var outc,count,cr,c,cst:longint;
    rot,maxst,st,sp,ss,cnt,first,next,v:array[0..maxn]of longint;

function get(i:longint):longint;
var j,c:longint;
begin
  c:=0;
  for j:=i+count-1 downto i+count-20 do
    if (j<=2*count)and(j>=i) then
      if sp[j]+j-i>c then
        c:=sp[j]+j-i;
  get:=c;
end;

function getrotate(var x:longint):longint;
var j,i,best,besti:longint;
begin
  for i:=1 to count do
    sp[count+i]:=sp[i];
  best:=inf;
  for i:=1 to count do
    begin
      j:=get(i);
      if j<best then
        begin
          best:=j;
          besti:=i;
        end;
    end;
  getrotate:=besti;
  x:=best;
end;

procedure run2(i:longint);
var cc,l,j,k:longint;
begin
  if cnt[i]=0 then
    begin
      if 1>outc then
        outc:=1;
      maxst[i]:=1;
      exit;
    end;
  k:=first[i];
  while k>0 do
    begin
      run2(v[k]);
      k:=next[k];
    end;
  k:=first[i];
  count:=0;
  while k>0 do
    begin
      inc(count);
      sp[count]:=maxst[v[k]];
      k:=next[k];
    end;
  j:=getrotate(cc);
  rot[i]:=j;
  if cc>outc then
    outc:=cc;
  maxst[i]:=cc;
end;

procedure run1(i:longint);
var l,k:longint;
begin
  if cnt[i]=0 then
    begin
      write('a');
      exit;
    end;
  k:=first[i];
  for l:=1 to rot[i]-1 do
    k:=next[k];
  for l:=1 to cnt[i]-rot[i]+1 do
    begin
      run1(v[k]);
      k:=next[k];
    end;
  k:=first[i];
  for l:=1 to rot[i]-1 do
    begin
      run1(v[k]);
      k:=next[k];
    end;
  write(cnt[i]);
end;

var
  s : string;

procedure addone;
begin
  inc(c);
  cnt[c]:=0;
  first[c]:=0;

  inc(cst);
  st[cst]:=c;
end;

procedure union(i:longint);
var j:longint;
begin
  inc(c);
  cnt[c]:=i;
  first[c]:=0;

  for j:=cst downto cst-i+1 do
    begin
      inc(cr);
      v[cr]:=st[j];
      next[cr]:=first[c];
      first[c]:=cr;
    end;
  dec(cst,i-1);
  st[cst]:=c;
end;

procedure dotree;
var i:longint;
begin
  c:=0;
  cst:=0;
  cr:=0;
  for i:=1 to length(s) do
    if s[i]='a' then
      addone
    else
      union(ord(s[i])-ord('0'));
end;

begin
  assign(input, 'chandelier.in');
  reset(input);
  assign(output, 'chandelier.out');
  rewrite(output);

  readln(s);
  dotree;

  if s<>'' then
    begin
      run2(c);
      writeln(outc);
      run1(c);
    end
  else
    writeln(0);

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