#include <stdio.h>
struct Ring;

#define max(A,B) (((A)>(B))?(A):(B))
#define min(A,B) (((A)<(B))?(A):(B))

#define P_A ((Ring *)1)

const inf=1000000;

char str[10005];

int spos, memlen;

struct Ring
{
	int N;
	Ring* R[9];
	int SS;
	int Shift;
	Ring(){;}
	~Ring(){;}
	int calc()
	{
		SS=max(1,N);
		int A[20];
		int i;
		for (i=0;i<N;i++)
		{
			if (R[i]!=P_A)
			{
				A[i]=R[i]->calc();
			}
			else
			{
				A[i]=1;
			}
		}
		for (i=N;i<20;i++) A[i]=A[i-N];
		SS=inf;
		for (int shift=0;shift<N;shift++)
		{
			int s=N;
			for (i=N-1;i>=0;i--)
			{
				s=max(s,N-1-i+A[i+shift]);
			}
			if (s<SS)
			{
				Shift=shift;
				SS=s;
			}
		}
		return SS;
	}
	void write(FILE *f)
	{
		int i;
		for (i=N+Shift-1;i>=Shift;i--)
		{
			int j=(i<N)?i:(i-N);
			if (R[j]!=P_A)
			{
				R[j]->write(f);
			}
			else
			{
				fprintf(f,"a");
			}
		}
		fprintf(f,"%i",N);
	}
};

Ring mem[10000];

char tmp[10001];

int str2mem()
{
	char c=str[spos];
	spos--;
	if (c=='a') return -1;
	int N=c-'0';
	int memthis=memlen;
	mem[memthis].N=N;
	memlen++;
	for (int i=0;i<N;i++)
	{
		int k=str2mem();
		if (k==-1)
		{
			mem[memthis].R[i]=P_A;
		}
		else
		{
			mem[memthis].R[i]=mem+k;
		}
	}
	mem[memthis].SS=-1;
	mem[memthis].Shift=-1;
	return memthis;
}

void readstr(FILE *f)
{
	spos=-1;
	char c=0;
	int i=1;
	while (c!='a' && (c<'0' || c>'9')) i=fscanf(f,"%c",&c);
	while (i==1 && (c=='a' || (c>='0' && c<='9')))
	{
		spos++;
		str[spos]=c;
		i=fscanf(f,"%c",&c);
	}
}

int main()
{
	FILE *f = fopen("chandelier.in","rt");
	readstr(f);
	memlen=0;
	int First=str2mem();
	fclose(f);
	
	f = fopen("chandelier.out","wt");
	if (First==-1)
	{
		fprintf(f,"1\na");
	}
	else if (First!=0)
	{
		fprintf(f,"где-то тут an error");
	}
	else
	{
		mem[0].calc();
		fprintf(f,"%i\n",max(1,mem[0].SS));
		mem[0].write(f);
	}
	fclose(f);
	return 0;
}