program Project2;

{$APPTYPE CONSOLE}

Var
        S : AnsiString;
        N : LongInt;
        KolSt : LongInt;
        Otv, F, St : Array[1..30000] Of LongInt;
        A : Array[1..30000, 0..9] Of LongInt;

Procedure InputData;
Begin
        Assign(input, 'chandelier.in');
        Reset(input);
        ReadLn(S);
        Close(input);
End;

Procedure BuildTree;

Var
        i, Num, j, Min, Otv : LongInt;
        
Begin
        N:= 0;
        KolSt:= 0;
        FillChar(A, SizeOf(A), 0);
        For i:= 1 To Length(S) Do
        Begin
                If S[i] = 'a' Then
                Begin
                        Inc(N);
                        Inc(KolSt);
                        St[KolSt]:= N;
                End Else
                Begin
                        Num:= Ord(S[i]) - 48;
                        For j:= KolSt-Num+1 To KolSt Do
                        Begin
                                  A[N+1, 0]:= A[N+1, 0] + 1;
                                  A[N+1, A[N+1, 0]]:= St[j];
                        End;
                        Dec(KolSt, Num);
                        
                        Inc(N);
                        Inc(KolSt);
                        St[KolSt]:= N;
                End;
        End;
End;

Function DFS(Num : LongInt) : LongInt;

Var
        j, i, s, Numb, min : LongInt;

Begin
        For i:= 1 To A[Num, 0] Do
        Begin
                If F[A[Num, i]] = -1 Then
                        F[A[num, i]]:= DFS(A[num, i]);
        End;

        If A[Num, 0] = 0 Then
        Begin
                F[num]:= 1;
                DFS:= 1;
        End Else
        Begin
                Min:= 1000000;
                For i:= 1 TO A[Num, 0] Do
                Begin
                        S:= 0;
                        Numb:= 0;
                        For j:= i To A[Num, 0] Do
                        Begin
                         if F[A[num,j]] + Numb > S Then
                                S:= F[a[num,j]] + Numb;
                         Inc(Numb);
                        End;

                        For j:= 1 To i-1 Do
                        Begin
                         if F[a[num,j]] + Numb > S Then
                                S:= F[a[num,j]] + Numb;
                         Inc(Numb);
                        End;
                        If S < Min Then
                        Begin
                                Min:= S;
                                Otv[Num]:= i;
                        End;
                End;
               F[Num]:= Min;
               DFS:= Min;
        End;
End;

Procedure Go(Num : LongInt) ;

Var
        j, i, s, Numb, min : LongInt;

Begin

        If A[Num, 0] = 0 Then
        Begin
                Write('a');
        End Else
        Begin

                For i:= Otv[num] TO A[Num, 0] Do
                Begin
                        Go(A[num, i]);
                End;

                For i:= 1 TO Otv[Num]-1 Do
                Begin
                        Go(A[num, i]);
                End;
                Write(A[num, 0]);
     
        End;
End;


Procedure Solve;

Var
        i : LongInt;
        
Begin
        BuildTree;

        For i:= 1 To N Do
         F[i]:= -1;
        F[N]:= DFS(N);
End;

Procedure OutputData;
Begin
        Assign(output, 'chandelier.out');
        Rewrite(output);
        Writeln(F[N]);
        Go(N);
        Writeln;
        Close(output);
End;

begin
  InputData;
  Solve;
  OutputData;
end.
 