#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <math.h>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define IREP(i,n) for (i = 0; i < (n); i++)

struct Node {
   bool leaf;
   vector<Node*> c;
   int best;
   int d;

   Node():leaf(true) {}

   void rec() {
      if (leaf) {
         d = 1;
      } else {
         d = 10000000;
         int n = c.size();
         for (int zz = 0; zz < n; ++zz) c[zz]->rec();
         for (int i = 0; i < n; ++i) {
            int cd = 0;
            for (int j = 0; j < n; ++j) {
               int k = (i+j)%n;
               if (c[k]->d + j > cd) 
                  cd = c[k]->d + j;
            }
            if (cd < d) {
               d = cd;
               best = i;
            }
         }
      }
   }

   void print(ofstream& out) {
      if (leaf) {
         out << 'a';
      } else {
         int n = c.size();
         for (int j = 0; j < n; ++j) {
            c[(best+j)%n]->print(out);
         }
         out << n;
      }
   }
};

vector<Node*> st;

int main()
{
   ifstream ifs("chandelier.in");
   ofstream ofs("chandelier.out");

   string s;
   ifs >> s;
   for (int i = 0; i < s.size(); ++i) {
      if (s[i] == 'a') {
         st.push_back(new Node());
      } else {
         Node* n = new Node();
         n->leaf = false;
         int sz = s[i]-'0';
         for (int k = 0; k < sz; ++k) {
            n->c.push_back(st[st.size()-sz+k]);
         }
         st.resize(st.size()-sz);
         st.push_back(n);
      }
   }

   st.back()->rec();
   ofs << st.back()->d << endl;
   st.back()->print(ofs);
   ofs << endl;

   return 0;
}