#include <bits/stdc++.h>
std::vector<int> g[500001];
int n, maxd;
int num[500001], sum[500001];
char ch;
std::string s[500001];
int max(int a, int b) { return a > b ? a : b; }
void dfs(int x, int d) {
  int i, t;
  g[d].push_back(x);
  maxd = max(maxd, d);
  sum[x] = 1;
  for (i = 1; i <= num[x]; i++) {
    t = x + sum[x];
    dfs(t, d + 1);
    sum[x] += sum[t];
  }
}
int main() {
  int i = 1, j;
  while ((ch = getchar()) != '\n') {
    if (ch == ',') {
      i++;
      continue;
    }
    if (i & 1)
      s[(i + 1) / 2] += ch;
    else
      (num[i / 2] *= 10) += ch - '0';
    n = (i + 1) / 2;
  }
  i = 1;
  while (i <= n) {
    dfs(i, 1);
    i += sum[i];
  }
  printf("%d\n", maxd);
  for (i = 1; i <= maxd; i++) {
    for (j = 0; j < g[i].size(); j++) std::cout << s[g[i][j]] << " ";
    puts("");
  }
  return 0;
}
