{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $01000000}
{$apptype console}
{ $q+,r+,o-}
{$q+,r+,o+}
{ $q-,r-,o+}

uses
  math, sysutils;

type
  int = longint;
  bool = boolean;
  float = extended;
  tb = record
    s : string;
    best : int;
  end;

const
  fn = 'chandelier';

var
  s : string;

function findmax(var idx : int) : tb;
var
  c : char;
  curbest, i, ic : int;
  s1 : array[0..15] of tb;
  cs, bs, csh, bsh: integer;
begin
  if s[idx] = 'a' then begin
    result.best := 1;
    result.s := 'a';
    dec(idx);
    exit;
  end;

  c := s[idx]; ic := strtoint(c); dec(idx);
  for i := 1 to ic do begin
    s1[i] := findmax(idx);
  end;

  bsh := 1;
  for csh := 2 to ic do begin
    for i := 1 to ic do begin
      bs := bsh-i+1; while ( bs > ic ) do bs := bs - ic; while ( bs < 1 ) do bs := bs + ic;
      cs := csh-i+1; while ( cs > ic ) do cs := cs - ic; while ( cs < 1 ) do cs := cs + ic;
      if ( s1[cs].best > s1[bs].best ) then begin
        bsh := csh;
        break;
      end else if ( s1[cs].best < s1[bs].best ) then begin
        break;
      end;
    end;
  end;

  result.s := ''; result.best := 0; curbest := 0;
  for i := bsh downto 1 do begin
    result.s := result.s + s1[i].s;
    if result.best < curbest + s1[i].best then
      result.best := curbest + s1[i].best;
    inc(curbest);
  end;
  for i := ic downto bsh + 1 do begin
    if result.best < curbest + s1[i].best then
      result.best := curbest + s1[i].best;
    result.s := result.s + s1[i].s;
    inc(curbest);
  end;
  result.s := result.s + c;
  if curbest > result.best then result.best := curbest;
end;

var
  len : int;
  ss : tb;

begin
  reset(input, fn + '.in');
  rewrite(output, fn + '.out');

  readln(s);
  len := length(s);
  ss := findmax(len);
  writeln(ss.best);
  writeln(ss.s);

end.

