{$R+,Q+,O-}
const
  MAX = 10100;
type
  TNode = record
    n: integer;
    a: array[1..9] of integer;
    min: integer;
  end;
var
  x: array[1..MAX] of TNode;
  st: array[1..MAX] of integer;
  s: string;
  i, j, cnt, top: integer;

function f(i: integer): integer;
var
  j, k, m: integer;
  s: array[1..20] of integer;
begin
  if (x[i].n = 1) and (x[i].a[1] = 0) then begin
    f := 1;
    exit;
  end;

  for j := 1 to x[i].n do begin
    s[x[i].n-j+1] := f(x[i].a[j]);
    s[x[i].n-j+1+x[i].n] := s[j];
  end;

  Result := MAXINT;
  for k := 1 to x[i].n do begin
    m := 0;
    for j := k to k + x[i].n - 1 do
      if j-k+1 + s[j]-1 > m then
        m := j-k+1 + s[j]-1;
    if m < result then begin
      result := m;
      x[i].min := k;
    end;
  end;
end;

procedure ff(i: integer);
var
  j, k: integer;
begin
  if (x[i].n = 1) and (x[i].a[1] = 0) then begin
    write('a');
    exit;
  end;

  j := x[i].min;
  for k := 1 to x[i].n do begin
    ff(x[i].a[j]);
    inc(j);
    if j > x[i].n then j := 1;
  end;

  write(x[i].n);
end;


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

  read(s);
  cnt := 0; top := 0;
  for i := 1 to Length(s) do begin
    if s[i] = 'a' then begin
      inc(cnt);
      x[cnt].n := 1; x[cnt].a[1] := 0;

      inc(top); st[top] := cnt;
    end
    else begin
      inc(cnt);
      x[cnt].n := ord(s[i]) - $30;
      for j := 1 to x[cnt].n do begin
        x[cnt].a[j] := st[top];
        dec(top);
      end;
      inc(top); st[top] := cnt;
    end;
  end;

  writeln(f(cnt));

  ff(cnt);
end.

