#include <bits/stdc++.h>
using namespace std;
char comments_encrypted[1000005], temp_comment[1000005];
typedef struct comments {
  char* comment;
  struct comments* next;
} c;
c* insert_comment(char* comm, c* root) {
  c* node = (c*)malloc(sizeof(c));
  node->next = NULL;
  node->comment = strdup(comm);
  if (root != NULL) root->next = node;
  return node;
}
c* comments_path[1000005][2];
int maximum(int a, int b) { return a > b ? a : b; }
void decrypt_comment_tree() {
  stack<int> children;
  int i, j, length, level = 0, child, depth = 0;
  length = strlen(comments_encrypted);
  for (i = 0; i < 1000005; i++) {
    comments_path[i][0] = comments_path[i][1] = NULL;
  }
  i = 0;
  while (i < length) {
    if (children.size()) {
      level = children.top();
      children.pop();
    } else
      level = 0;
    depth = maximum(depth, level);
    j = i;
    while (j < length && comments_encrypted[j] != ',') j++;
    strncpy(temp_comment, &comments_encrypted[i], j - i + 1);
    temp_comment[j - i] = '\0';
    comments_path[level][1] =
        insert_comment(temp_comment, comments_path[level][1]);
    if (comments_path[level][0] == NULL) {
      comments_path[level][0] = comments_path[level][1];
    }
    j++;
    i = j;
    child = 0;
    while (j < length && comments_encrypted[j] != ',') {
      child = child * 10 + (comments_encrypted[j] - '0');
      j++;
    }
    while (child > 0) {
      children.push(level + 1);
      child--;
    }
    i = j + 1;
  }
  cout << depth + 1 << endl;
  for (i = 0; i <= depth; i++) {
    c* node = comments_path[i][0];
    while (node) {
      cout << node->comment << " ";
      node = node->next;
    }
    cout << endl;
  }
  return;
}
int main() {
  cin >> comments_encrypted;
  decrypt_comment_tree();
  return 0;
}
