#include <iostream.h>
#include <stdio.h>
#include <ctype.h>


struct elem
{
	int used;
	int numc;
	elem ** c;
	int start;
} * stack[10000];
int sp;


void read( int ch )
{
  if ( ch  == 'a' )
  {
	  elem * n = new elem( );
	  n->numc = 1;
	  n->c = 0;
	  stack[sp++] = n;
  }
  else
  {
	  ch -= '0';
	  elem * n = new elem( );
	  n->numc = ch;
	  n->c = new elem*[ch];
	  for ( int i = 0; i < ch; ++i )
		  n->c[ ch - i - 1 ] = stack[--sp];
	  stack[sp++] = n;
	  n->start = 0;
  }
}


void write( elem * x ) 
{
	if ( x->c == 0 )
		printf( "a" );
	else
	{
		int i = x->start;
		for ( int j = 0; j < x->numc; ++j )
		{						
			write( x->c[i] );
			++i;
			if ( i == x->numc )
				i = 0;
		}
		printf("%d", x->numc );
	}
}



void go( elem * x ) 
{
	if ( x->c == 0 )
	{
		x->used = 1;
		return;
	}
	int i;
	for ( i = 0; i < x->numc; ++i )
		go( x->c[i] );
	int start = 0;
	int bu = 10000000, bs;
	for ( start = 0; start < x->numc; ++start )
	{
	  x->used = 0;
	  i = start;
	  for ( int j = 0; j < x->numc; ++j )
	  {						
	  	if ( x->used < j + x->c[i]->used )
			x->used = j + x->c[i]->used;
		++i;
		if ( i == x->numc )
			i = 0;
	  }
	  if ( x->used < bu )
	  {
		  bu = x->used;
		  bs = start;
	  }
	}
	x->used = bu;
	x->start = bs;
}

int main () 
{
	freopen("chandelier.in", "rt", stdin );
	freopen("chandelier.out", "wt", stdout );
	int ch = getchar( );
	while ( isdigit( ch ) || ch == 'a' )
	{
	  read( ch );
	  ch = getchar( );
	}
	go( stack[0] );
	printf("%d\n", stack[0]->used );
	write( stack[0] );
	printf("\n");
	return 0;
}