program taskc;
{$APPTYPE CONSOLE}
{$I+,Q+,R+,O-}
{ $I-,Q-,R-,O+}
uses
  SysUtils,Math;
type
  short=smallint;
  long=longint;
  real=extended;
  bool=boolean;
const
  maxn=10000;
var
  n,pos: long;
  a: array[1..maxn] of char;
  kids,sol: array[0..maxn,0..10] of long;

  procedure initkids;
  var
    cur,i: long;
  begin
    if a[pos]='a' then dec(pos)
    else begin
      cur:=pos;
      kids[cur,0]:=byte(a[pos]) and 15;
      dec(pos);
      for i:=kids[cur,0] downto 1 do begin
        kids[cur,i]:=pos;
        initkids;
      end;
    end;
  end;

  procedure solve(n: long);
  var
    i,j,cur,tmp,min,ibest: long;
  begin
    if kids[n,0]=0 then sol[n,0]:=1
    else begin
      for i:=1 to kids[n,0] do solve(kids[n,i]);
      min:=high(min); ibest:=-1;
      for i:=1 to kids[n,0] do begin
        cur:=0;
        for j:=1 to kids[n,0] do cur:=max(cur,j-1+sol[kids[n,j],0]);
        if cur<min then begin
          min:=cur;
          ibest:=i;
        end;
        tmp:=kids[n,1];
        for j:=1 to kids[n,0]-1 do kids[n,j]:=kids[n,j+1];
        kids[n,kids[n,0]]:=tmp;
      end;
      j:=0;
      for i:=ibest to kids[n,0] do begin
        inc(j);
        sol[n,j]:=kids[n,i];
      end;
      for i:=1 to ibest-1 do begin
        inc(j);
        sol[n,j]:=kids[n,i];
      end;
      sol[n,0]:=min;
    end;
  end;

  procedure print(n: long);
  var i: long;
  begin
    if kids[n,0]=0 then write('a')
    else begin
      for i:=1 to kids[n,0] do print(sol[n,i]);
      write(kids[n,0]);
    end;
  end;

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

  n:=0;
  while not seekeof do begin
    inc(n);
    read(a[n]);
  end;
  fillchar(kids,sizeof(kids),0);
  pos:=n;
  initkids;
  solve(n);
  writeln(sol[n,0]);
  print(n);

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

