{v$O-,I+,S+,R+,Q+,H-}

{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}

const
  cinfile = 'chandelier.in';
  coutfile = 'chandelier.out';
  inf = maxlongint shr 1;
  eps = 1E-8;

  nmax = 50000;

type
  int = longint;
  real = extended;
  float = extended;

  alph = array [0..10] of int;

var
  n, k, m : int;
  ans : int;

  kc : int;
  c : array [1..nmax] of alph;
  p : array [1..nmax] of alph;
  v : array [1..nmax] of int;

  kst : int;
  st : array [0..nmax] of int;

procedure outit(w : int);
var
  i, j : int;
begin
  for i:= 1 to c[w][0] do outit(c[w, p[w][i]]);
  if  c[w][0] = 0 then write('a') else write(c[w][0]);
end;

procedure outdata;
var
  i, j : int;
begin
  writeln(v[kc]);
  outit(kc);
  writeln;
end;

procedure go(w : int);
var
  i, j : int;
  x, buf, res : int;
  p2 : alph;
begin
  for i:= 1 to c[w][0] do go(c[w][i]);
  res:= inf;
  for i:= 1 to c[w][0] do p[w][i]:= i;
  fillchar(p2, sizeof(p2), 0);
  p2[0]:= c[w][0];
  p[w][0]:= c[w][0];
  for j:= 1 to c[w][0] do
  begin
    buf:= 1;
    for i:= 1 to c[w][0] do
      if buf < (i - 1) + v[c[w, p[w][i]]] then buf:= (i - 1) + v[c[w, p[w][i]]];
    if res > buf then
    begin
      p2:= p[w];
      res:= buf;
    end;
    x:= p[w][1];
    move(p[w][2], p[w][1], sizeof(p[w][1])*(p[w][0] - 1));
    p[w][p[w][0]]:= x;
  end;
  p[w]:= p2;
  if c[w][0] = 0 then res:= 1;
  v[w]:= res;
end;

procedure solve;
var
  i, j : int;
begin
  fillchar(v, sizeof(v), 0);
  fillchar(p, sizeof(p), 0);
  go(kc);
end;

procedure readdata;
var
  i, j : int;
  ch : char;
begin
  fillchar(c, sizeof(c), 0);
  kst:= 0;
  while not seekeof do
  begin

    read(ch);
    if ch = 'a' then
    begin
      inc(kc);
      inc(kst);
      st[kst]:= kc;
    end else
    begin
      j:= ord(ch) - ord('0');
      inc(kc);
      c[kc][0]:= j;
      for i:= 1 to j do
      begin
        c[kc][c[kc][0] - i + 1]:= st[kst];
        dec(kst);
      end;
      inc(kst);
      st[kst]:= kc;
    end;
    
  end;
end;

begin
  reset(input, cinfile);
  rewrite(output, coutfile);
  readdata;
  solve;
  outdata;
  close(output);
  close(input);
end.
