//c
#include <stdio.h>
#include <queue>
#include <stack>
using namespace std;
const int MAX = 16384;
const int INFINITY = 999999999; 
stack<int> iStack;
queue<int> q;
int n,iColor[MAX];
char s[MAX],sAns[MAX];

struct stNode {
	int n,ost,first,pred,succ[10],ans;
} zNode[MAX];

int Max(int x, int y) {
	return x>y?x:y;
}

int BuildTree() {
	int i,j,cur=0,count;
	for (i=0; s[i]!=0; i++)
		if (s[i]=='a')
			iStack.push(-1);
		else {
			cur++;
			count = s[i]-'0';
			zNode[cur].n = count;
			for (j=count-1; j>=0; j--) { //////////////////////////////////////////////////////////////
				zNode[cur].succ[j] = iStack.top();
				iStack.pop();
				zNode[zNode[cur].succ[j]].pred = cur;
			}
			iStack.push(cur);
		}
	for (i=1; i<=cur; i++) {
		count = 0;
		for (j=0; j<zNode[i].n; j++)
			if (zNode[i].succ[j]!=-1)
				count++;
		zNode[i].ost = count;
	}
	zNode[cur].pred = INFINITY;
	return cur;
}	

void Out(int ver) {
	int i,count;
	if (ver==-1) {
		putchar('a');
		return;
	}
	count = zNode[ver].n;
	for (i=0; i<count; i++)
		Out(zNode[ver].succ[(i+zNode[ver].first)%count]);		
	printf("%d",count);
}

void Solve() {
	int i,j,cur,count,root,iMin,iMinNum,iCurVal;
	root = count = BuildTree();
	for (i=1; i<=count; i++) {
		for (j=0; j<zNode[i].n; j++)
			if (zNode[i].succ[j]!=-1)
				break;
		if (j==zNode[i].n) {
			iColor[i] = 1;
			q.push(i);
			zNode[i].first = 0;
		}			
	}
	while (!q.empty()) {
		cur = q.front();
		q.pop();
		if (zNode[cur].pred!=INFINITY)
			zNode[zNode[cur].pred].ost--;
		if ((zNode[cur].pred!=INFINITY) && (zNode[zNode[cur].pred].ost==0)) {
			iColor[zNode[cur].pred] = 1;
			q.push(zNode[cur].pred);
		}
		iMin = INFINITY;
		for (i=0; i<zNode[cur].n; i++) {
			count = zNode[cur].n;
			if (zNode[cur].succ[i]==-1)
				iCurVal = 1;
			else
				iCurVal = zNode[zNode[cur].succ[i]].ans;
			for (j=1; j<count; j++)
				iCurVal = Max(iCurVal, j+(zNode[cur].succ[(i+j)%count]==-1?1:zNode[zNode[cur].succ[(i+j)%count]].ans));
			if (iCurVal<iMin) {
				iMin = iCurVal;
				iMinNum = i;
			}
		}
		zNode[cur].first = iMinNum;
		zNode[cur].ans = iMin;
	}
	printf("%d\n",zNode[root].ans);
	Out(root);
	printf("\n");
}

int main() {
	freopen("chandelier.in", "rt", stdin);
	freopen("chandelier.out", "wt", stdout);
	scanf("%s",s);
	Solve();
	return 0;
}