#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
int deep[maxn], c[maxn], f[maxn];
string str[maxn];
string tmp;
vector<int> G[maxn];
queue<int> Q;
int main() {
  int fa = 0, tot = 0, d = 0;
  while (getline(cin, str[++tot], ',')) {
    getline(cin, tmp, ',');
    for (int i = 0; i < tmp.length(); i++) c[tot] = c[tot] * 10 + tmp[i] - '0';
    f[tot] = fa;
    c[fa]--;
    deep[tot] = deep[fa] + 1;
    if (c[tot] != 0) {
      fa = tot;
    }
    while (c[fa] == 0) fa = f[fa];
  }
  tot--;
  for (int i = 1; i <= tot; i++) d = max(d, deep[i]);
  for (int i = 1; i <= tot; i++) G[f[i]].push_back(i);
  cout << d << endl;
  Q.push(0);
  while (!Q.empty()) {
    int N = Q.size();
    for (int i = 0; i < N; i++) {
      int x = Q.front();
      Q.pop();
      for (int j = 0; j < G[x].size(); j++) {
        int to = G[x][j];
        cout << str[to] << " ";
        Q.push(to);
      }
    }
    cout << endl;
  }
}
