#include <fstream>
#include <iostream>
#include <string.h>
#include <vector>

using namespace std;

ifstream fin("chandelier.in");
ofstream fout("chandelier.out");

char s[10001];
int ls;
struct node { char c; node *child, *next, *opt; int len, min; } n[10000];
int a[9], na; // apakshnieki
int imin, tmp;



// ielasa kokveidaa
void parse()
{
	int i, j, k;
	node *prev;
	
	for (i = 0; i < ls; i++) {
		n[i].c = s[i];
		if (s[i] == 'a') {
			n[i].len = 1;
		} else {
			n[i].len = 1;
			prev = NULL;
			for (j = i - 1, k = 0; k < n[i].c - '0'; j -= n[j].len, k++) {
				n[i].len += n[j].len;
				n[j].next = prev;
				prev = &n[j];
			}
			n[i].child = prev;
		}
	}
}



// apreekjina min un sakaarto (atrod opt)
void order(node *n)
{
	node *p;
	int i, j;

	if (n->c == 'a') {
		n->min = 1;
	} else {
		// sareekjina apakshniekus
		for (p = n->child; p; p = p->next) order(p);
		for (p = n->child, i = 0; p; p = p->next, i++) a[i] = p->min;
		// kvadraatiski... toch labaak nemaakam?
		n->min = 10000;
		na = n->c - '0';
		for (i = 0; i < na; i++) {
			tmp = 0;
			for (j = 0; j < na; j++) if (j + a[(i + j) % na] > tmp) tmp = j + a[(i + j) % na];
			if (tmp < n->min) n->min = tmp, imin = i;
		}
		// uzstaadaam opt
		n->opt = n->child;
		for (j = 0; j < imin; j++) n->opt = n->opt->next;
	}
}



// output
void print(node *n)
{
	node *p;

	if (n->c != 'a') {
		// apakshlustras
		if (n->opt == n->child) {
			for (p = n->opt; p; p = p->next) print(p);
		} else {
			// 2 gaajieni
			for (p = n->opt; p; p = p->next) print(p);
			for (p = n->child; p != n->opt; p = p->next) print(p);
		}
	}
	
	fout << n->c;
}



void debug_print(node *n)
{
	node *p;

	if (n->c != 'a') {
		cout << '(';
		for (p = n->child; p; p = p->next) debug_print(p);
		cout << ')';
	}
	cout << n->c << '[' << n->min << ']';
}



int main()
{
	fin >> s;
	ls = strlen(s);

	parse();
//	debug_print(&n[ls - 1]);
	order(&n[ls - 1]);
//	debug_print(&n[ls - 1]);

	fout << n[ls - 1].min << '\n';
	print(&n[ls - 1]);
	
	return 0;
}