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

function get(i:longint):longint;
var l:longint;
begin
  l:=nsp[i+1]-nsp[i];
  if l<0 then
    l:=l+count;
  get:=sp[nsp[i]]+count-l;
end;

function getrotate:longint;
var cup,j,i,bst,bsti:longint;
    f:boolean;
begin
  for i:=1 to count do
    sp[count+i]:=sp[i];
  for i:=1 to count do
    sp[2*count+i]:=sp[i];
  nc:=0;
  i:=1;
  fillchar(up,sizeof(up),0);
  while i<=2*count do
    begin
      j:=i+1;
      while (j<=3*count)and(sp[j]+j-i<=sp[i]) do
        inc(j);
      inc(nc);
      nsp[nc]:=j;
      f:=(j>count);
      while nsp[nc]>count do
        dec(nsp[nc],count);
      if f then
        up[nsp[nc]]:=1;
      i:=j;
    end;
  j:=0;
  for i:=1 to nc do
    if up[nsp[i]]=1 then
      begin
        inc(j);
        nsp[j]:=nsp[i];
     end;
  cup:=0;
  for i:=1 to count do
    if up[i]=1 then
      inc(cup);
  nc:=cup;
  inc(nc);
  nsp[nc]:=nsp[1];
  bst:=inf;
  for i:=1 to nc-1 do
    begin
      j:=get(i);
      if j<bst then
        begin
          bst:=j;
          bsti:=nsp[i+1];
        end;
    end;
  getrotate:=bsti;
end;

procedure run(i:longint);
var cp,l,j,k:longint;
begin
  if cnt[i]=0 then
    begin
      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.