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

struct it
{
  it *next, *prev, *child, *last, *best;
  int d, n;
} *stack;

char str[10005];
int cnt;

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

void traverse(it *p)
{
it *q, *t;
int d, i;
  p->n = 0;
  if(p->child == 0) { p->d = 1; return; }
  for(q = p->child; q; q = q->next)
  {
    if(q->next == 0) p->last = q;
    traverse(q);
    ++p->n;
  }
  p->d = -1;
  for(q = p->child; q; q = q->next)
  {
    d = 0;
    t = q;
    for(i = 0; i < p->n; i++)
    {
      d = max(d, i+t->d);

      t = t->prev;
      if(t == 0) t = p->last;
    }
    if(p->d == -1 || d < p->d) { p->d = d; p->best = q; }
  }
}

void output(it *p)
{
it *q;
int i;
  if(p->child == 0) { putchar('a'); return; }
  q = p->best;
  for(i = 0; i < p->n; i++)
  {
    output(q);

    q = q->prev;
    if(q == 0) q = p->last;
  }
  printf("%d", p->n);
}

int main(void)
{
int i, j;
it *t, *q;
  freopen("chandelier.in",  "rt", stdin);
  freopen("chandelier.out", "wt", stdout);
  gets(str);
  for(i = 0; str[i]; i++)
  {
    if(isalpha(str[i]))
    {
      if(!stack)
      {
        stack = new it;
        stack->next = 0;
        stack->prev = 0;
        stack->child = 0;
      }
      else
      {
        t = new it;
        t->prev = 0;
        t->next = stack;
        t->child = 0;
        stack->prev = t;
        stack = t;
      }
    }
    else
    {
      t = new it;
      t->child = stack;
      q = stack;
      for(j = 0; j < str[i]-'0'-1; j++) q = q->next;
      t->next = q->next;
      if(t->next) t->next->prev = t;
      q->next = 0;
      t->prev = 0;
      stack = t;
    }
  }
  traverse(stack);
  printf("%d\n", stack->d);
  output(stack);
  putchar('\n');
  return 0;
}