{$APPTYPE CONSOLE}
{$O-,R+,Q+}
uses
  Sysutils, Math;
const
  inf = 1000000000;
  eps = 1e-9;
  base = 10;
type
  int = longint;
  bool = boolean;
  real = extended;
  tring = record
    n: int;
    first: int;
    len: int;
    child: array of int;
  end;

var
  i, j, k, n, m, nn: int;
  str: string;
  t, num: int;
  s: array[0..10000] of longint;
  ring: array[0..10000] of tring;
  mx, mxi, sum, ans: int;
  
function optimize(k: int): int;
var
  i, j: int;
begin
  if ring[k].n = 0 then
  begin
    result := 1;
    ring[k].len := 1;
    ring[k].first := 0;
    exit;
  end;
  for i := 1 to ring[k].n do
    optimize(ring[k].child[i]);
  mx := 0;
  mxi := -1;
  for i := 1 to ring[k].n do
    if ring[ring[k].child[i]].len > mx then
    begin
      mx := ring[ring[k].child[i]].len;
      mxi := i;
    end;
  ring[k].first := mxi;
  ans := 0;
  for i := ring[k].first + 1 to ring[k].n do
  begin
    sum := (i - ring[k].first) + ring[ring[k].child[i]].len;
    if sum > ans then
      ans := sum;
  end;
  for i := 1 to ring[k].first - 1 do
  begin
    sum := ring[k].n - ring[k].first + i + ring[ring[k].child[i]].len;
    if sum > ans then
      ans := sum;
  end;
  result := max(ans, mx);
  ring[k].len := result;
end;

procedure toout(k: int);
var
  i: int;
begin
  if ring[k].n = 0 then
  begin
    write('a');
    exit;
  end;
  toout(ring[k].child[ring[k].first]);
  for i := ring[k].first + 1 to ring[k].n do
    toout(ring[k].child[i]);
  for i := 1 to ring[k].first - 1 do
    toout(ring[k].child[i]);
  write(ring[k].n);
end;

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

  t := 0;
  num := 0;
  for i := 1 to length(str) do
  begin
    if str[i] = 'a' then
    begin
      inc(t);
      inc(num);
      s[t] := num;
      ring[num].n := 0;
    end else if str[i] in ['1'..'9'] then
    begin
      nn := ord(str[i]) - ord('0');
      inc(num);
      ring[num].n := nn;
      ring[num].first := 1;
      setlength(ring[num].child, nn + 1);
      for k := 1 to nn do
      begin
        ring[num].child[nn - k + 1] := s[t];
        dec(t);
      end;
      inc(t);
      s[t] := num;
    end;
  end;
  writeln(optimize(s[t]));
  toout(s[t]);
  close(input);
  close(output);
end.
//Leafy tops of root vegetables strike back...