#include <stdio.h>

#define NN 11000
#define LL 9

FILE *fi, *fo;
int a[NN];
int ans[NN];
int d[NN];
int b[NN][LL];
int stk[NN];
int n,m;

int max(int a, int b) {
	return (a>b)?a:b; 
}

int min(int a, int b) {
	return (a<b)?a:b; 
}

int getcc() {
	int c;
	c=getc(fi);
	while((c==' ')||(c=='\n')||(c=='\r')||(c=='\t')) {
		c=getc(fi);
	}
	return c;
}

void pop(int v) {
	int i;
	for(i=0;i<v;i++) {
		b[n][v-i-1]=stk[--m];
	}
	stk[m++]=n;
}

int calc(int f) {
	int i,j,best,t;
	d[f]=-1;
	if(a[f]==0) return 1;
	best=1000000000;
	for(j=0;j<a[f];j++) {
		t=1;
		for(i=0;i<a[f];i++) {
			t=max(t,ans[b[f][(j+i)%a[f]]]+i);
		}
		if(t<best) {
			best=t;
			d[f]=j;
		}
	}
	return best;
}

void wr(int f) {
	int i;
	if(d[f]<0) {
		fprintf(fo,"a");
	} else {
		for(i=0;i<a[f];i++) {
			wr(b[f][(d[f]+i)%a[f]]);
		}
		fprintf(fo,"%d",a[f]);
	}
}

int main() {
	int c;
	int i;
	fi=fopen("chandelier.in","rt");
	fo=fopen("chandelier.out","wt");

	n=0; m=0;
	while((c=getcc())!=EOF) {
		if(c=='a') {
			stk[m++]=n;
			a[n++]=0;
		} else {
			pop(c-'0');
			a[n++]=c-'0';
		}
	}
	for(i=0;i<n;i++) {
		ans[i]=calc(i);
	}
	fprintf(fo,"%d\n",ans[n-1]);
	wr(n-1);
	fprintf(fo,"\n");

	fclose(fi);
	fclose(fo);
	return 0;
}