{$DEFINE DEBUG}

{$IFDEF DEBUG}
{$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}
{$ELSE}
{$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}
{$ENDIF}

{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $02000000}
{$APPTYPE CONSOLE}

uses
  Math, SysUtils;

const
  maxp = 12;
  maxst = 11000;

type
  int = longint;
  float = extended;
  pnode = ^tnode;
  tnode = record
    a : array[1..maxp] of pnode;
    cnt,bsu,stv : int;
  end;

const
  cin_file = 'chandelier.in';
  cout_file = 'chandelier.out';
  eps : float = 1e-9;
  fmax : float = 1e40;
  besk = $3F3F3F3F;

var
  stc,n : int;
  st : array[1..maxst] of pnode;

procedure rec(var a : pnode);
var
  i,j,st,t : int;
begin
  if a <> nil then
  begin
    if a.cnt = 0 then
    begin
      a^.bsu:=1;
    end else
    begin
      for i:=1 to a^.cnt do rec(a^.a[i]);
      a.bsu := besk;
      for st := 1 to a.cnt do
      begin
        t := a.a[st].bsu;
        j := st;
        for i := 1 to a.cnt - 1 do
        begin
          dec(j);
          if j < 1 then
            j := a.cnt;
          if t < i + a.a[j].bsu then
            t := i + a.a[j].bsu;
        end;
        if a.bsu > t then
        begin
          a.bsu := t;
          a.stv := st;
        end;
      end;
    end;
  end;
end;

procedure print(a : pnode);
var
  i,j : int;
begin
  if a <> nil then
  begin
    if a.cnt = 0 then
      write('a')
    else
    begin
      j:=a^.stv;
      for i:=1 to a^.cnt do
      begin
        print(a^.a[j]);
        dec(j);
        if j < 1 then j:=a^.cnt;
      end;
      write(a^.cnt);
    end;
  end;
end;

procedure solve;
var
  i : int;
  ch : char;
  p : pnode;
begin
  stc:=0;
  fillchar(st, sizeof(st), 0);
  while not seekeoln do
  begin
    read(ch);
    if ch = 'a' then
    begin
      inc(stc);
      new(st[stc]);
      fillchar(st[stc]^, sizeof(st[stc]^), 0);
    end;
    if ch in ['1'..'9'] then
    begin
      new(p);
      fillchar(p^, sizeof(p^), 0);
      for i:=1 to ord(ch) - ord('0') do
      begin
        inc(p^.cnt);
        assert(stc > 0);
        p^.a[p^.cnt]:=st[stc];
        dec(stc);
      end;
      inc(stc);
      st[stc]:=p;
    end;
  end;

  assert(stc = 1);
  rec(st[stc]);

  writeln(st[stc].bsu);
  print(st[stc]);
end;

begin
  assign(input, cin_file);
  reset(input);
  assign(output,  cout_file);
  rewrite(output);

  solve;

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