#include<algorithm>
#include"vector"
#include<string>
#include<iostream>
#include<fstream>
using namespace std;

ifstream fi("chandelier.in");
ofstream fo("chandelier.out");
typedef vector<int> veci;typedef vector<double> vecd;typedef vector<string> vecs;

#define forn(i,n) if(true)for(int i=0;i<(n);i++)
#define feach(i,v) forn(i,((int)v.size()))
#define VA(v) v.begin(),v.end()

struct tnode{
	vector<tnode*> a;
};

typedef pair<int,tnode*> tpair;

int ls(tpair&a,tpair&b){
	return a.first>b.first;
}

int rec(tnode *node){
	if(!node) return 1;
	vector<tpair> v;
	feach(i,node->a){
		int s=rec(node->a[i]);
		pair<int,tnode*> pp;
		pp.first=s;
		pp.second=node->a[i];
		v.push_back(pp);
	}
	//sort(VA(v),ls);

	int n=node->a.size();

	int mm=-1,md=0;
	for(int d=0;d<n;d++){
		int c,m=0;
		feach(i,node->a){
			c=i+v[(i+d)%n].first;
			if(c>m) m=c;
		}
		if(mm<0 || mm>m){
			mm=m;
			md=d;
		}
	}
	feach(i,node->a){
		node->a[i]=v[(i+md)%n].second;
	}
	return mm;
}

void outp(tnode *node){
	if(!node){fo<<"a";return;}
//	fo<<"(";
	feach(i,node->a){
		outp(node->a[i]);
	}
//	fo<<")";
	fo<<node->a.size();
}

int main(){
	vector<tnode*> h;

	char s[10001];
	fi>>s;
	string inp=s;

	feach(i,inp){
		char ch=s[i];
		if(ch=='a'){
			h.push_back(0);
		}else{
			int z=ch-'0';
			tnode *nn=new tnode();
			int hs=h.size();
			forn(j,z){
				nn->a.push_back(h[hs-z+j]);
			}
			h.erase(h.begin()+hs-z,h.begin()+hs-z+z-1);
			h[h.size()-1]=nn;
		}
	}

	//outp(h[0]);

	int ret=rec(h[0]);
	fo<<ret<<endl;
	outp(h[0]);

	return 0;
}