#include <fstream>

using namespace std;

ofstream out;

struct Tree
{
	int best, first, n;
	Tree * children[10];
	Tree():first(0) {};
};

int top = 0;
Tree * stack[10000+5];

Tree * build(char *c)
{
	for (; *c; ++c)
	{
		if (*c == 'a')
			stack[top++] = NULL;
		else if (*c >= '1' && *c <= '9')
		{
			Tree *t = new Tree;
			t->n = *c - '0';
			for (int i = t->n-1; i >= 0; --i)
			{
				t->children[i] = stack[--top];
			}
			stack[top++] = t;
		}
	}
	return stack[0];
}

void optimize(Tree * t)
{
	int i, shift;
	t->best = 100000;
	for (i = 0; i < t->n; ++i)
		if (t->children[i])
			optimize(t->children[i]);

	for (shift = 0; shift < t->n; ++shift)
	{
		int max = 0;
		for (i = 0; i < t->n; ++i)
		{
			int cur = 1;
			if (t->children[(i+shift)%t->n])
				cur = t->children[(i+shift)%t->n]->best;
			if (i + cur > max)
				max = i + cur;
		}
		if (max < t->best)
		{
			t->best = max;
			t->first = shift;
		}
	}
}


void print(Tree * t)
{
	if (!t)
	{
		out << 'a';
		return;
	}
	int i;
	for (i = t->first; i < t->n; ++i)
		print(t->children[i]);
	for (i = 0; i < t->first; ++i)
		print(t->children[i]);
	out << char(t->n + '0');
}

int main()
{
	char str[10000 + 5];

	ifstream in("chandelier.in");
	out.open("chandelier.out");

	in >> str;

	Tree * t = build(str);
	optimize(t);
	if (!t)
		out << 1 << '\n';
	else
		out << t->best << '\n';
	print(t);
	out << '\n';

	in.close();
	out.close();
	return 0;
}
