program chandelier;

{$APPTYPE CONSOLE}
{$R-,S-,Q-,I-,O+}

const
    FILE_IN = 'chandelier.in';
    FILE_OUT = 'chandelier.out';
    MAX_N = 10000 + 1; 

type
    PTTreeNode = ^TTreeNode;
    TTreeNode = record
        max, sh : longint;
        a : array of PTTreeNode;
    end;

var
    s : string;
    tree : PTTreeNode;

procedure Process ( tree : PTTreeNode );
var
    w, q, i, j : longint;
begin
    if length(tree^.a) = 0 then
    begin
        tree^.sh := 0;
        tree^.max := 1;
        exit;
    end;
    for i:=0 to length( tree^.a ) - 1 do
        process ( tree^.a[i] );
//////// 
    j:=0;
    with tree^ do
    for i:=1 to length( a ) - 1 do
        if length(a[i]^.a) <> length(a[i-1]^.a) then
        begin
            j := 1;
            break;
        end;
    if j = 0 then
    begin
        tree^.sh := 0;
        tree^.max := length(tree^.a[0]^.a)+length(tree^.a)-1;
        exit;
    end;

/////////////////////////////////////////////////////
    tree^.max := MAXLONGINT;
    with tree^ do
    for i:=0 to length( a ) - 1 do
    begin
        q := 0;
        j := 0;
        for w:=i to length(a)-1 do
        begin
            if length(a[w]^.a)+j > q then
                q := length(a[w]^.a)+j;
            inc ( j );
        end;
        for w:=0 to i-1 do
        begin
            if length(a[w]^.a)+j > q then
                q := length(a[w]^.a)+j;
            inc ( j );
        end;
        if q < max then
        begin
            max := q;
            sh := i;
        end;
    end;
end; // process

procedure maketree ( var tree : PTTreeNode );
var
    stack : array [1..MAX_N] of PTTreeNode;
    tmp : PTTreeNode;
    i, j, last : longint;
begin
    last := 0;
    for i:=1 to length(s) do
    begin
        new ( tmp );
        tmp^.a := nil;
        tmp^.max :=0;
        tmp^.sh :=0;
        if s[i] <> 'a' then
        begin
            SetLength ( tmp^.a, ord(s[i])-ord('0') );
            for j:=length(tmp^.a) downto 1 do
            begin
                tmp^.a[j-1] := stack[last];
                dec ( last );
            end;
        end;
        inc ( last );
        stack[last] := tmp;
    end;
    tree := stack[last];
end;

procedure WriteTree ( tree : PTTreeNode );
var
    i : longint;
begin
    for i:=tree^.sh to length ( tree^.a ) - 1 do
        WriteTree ( tree^.a[i] );
    for i:=0 to tree^.sh-1 do
        WriteTree ( tree^.a[i] );
    if length ( tree^.a ) = 0
        then write ( 'a' )
        else write ( length ( tree^.a ) );
end;

begin
    assign ( input, FILE_IN );
    assign ( output, FILE_OUT );
    reset ( input );
    readln ( s );
    close ( input );

    maketree ( tree );

    process ( tree );    

    rewrite ( output );
    WriteTree ( tree );
    close ( output );
end.
 