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

function get(i:longint):longint;
var j,c:longint;
begin
  c:=0;
  for j:=i+count-1 downto i+count-12 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: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;
end;

procedure run(i:longint);
var cp,l,j,k:longint;
begin
  if cnt[i]=0 then
    begin
      if 1>outc then
        outc:=1;
      outs:=outs+'a';
      exit;
    end;
  count:=cnt[i];
  k:=first[i];
  for j:=1 to count do
    begin
      sp[j]:=cnt[v[k]];
      if sp[j]=0 then
        sp[j]:=1;
      ss[j]:=k;
      k:=next[k];
    end;
  j:=getrotate;
  k:=ss[j];
  for l:=1 to cnt[i]-j+1 do
    begin
      cp:=cnt[v[k]];
      if cp=0 then
        cp:=1;
      cp:=cp+l-1;
      if cp>outc then
        outc:=cp;
      run(v[k]);
      k:=next[k];
    end;
  k:=first[i];
  for l:=1 to j-1 do
    begin
      cp:=cnt[v[k]];
      if cp=0 then
        cp:=1;
      cp:=cp+cnt[i]-j+l;
      if cp>outc then
        outc:=cp;
      run(v[k]);
      k:=next[k];
    end;
  outs:=outs+inttostr(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;

  outs:='';
  run(c);
  writeln(outc);
  writeln(outs);

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