#include <bits/stdc++.h>
using namespace std;
int const N = 1e6 + 10;
string s;
stack<pair<int, int> > Stk;
int cont;
map<string, int> id;
map<int, int> d;
vector<string> P[N];
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  int num = 0, maior = 0;
  int last = -1;
  for (int i = 0; i < s.size(); i++) {
    int j;
    int val = 0;
    string node;
    for (j = i; j < s.size() && s[j] != ','; j++) {
      if (num)
        val = val * 10 + (s[j] - '0');
      else
        node.push_back(s[j]);
    }
    if (num)
      Stk.push(pair<int, int>(last, val));
    else {
      id[node] = ++cont;
      last = id[node];
      int root = id[node];
      if (Stk.empty()) {
        d[root] = 1;
        P[1].push_back(node);
        maior = max(maior, 1);
      } else {
        int par = Stk.top().first;
        int total = Stk.top().second;
        d[root] = d[par] + 1;
        Stk.pop();
        Stk.push(pair<int, int>(par, total - 1));
        maior = max(maior, d[root]);
        P[d[root]].push_back(node);
      }
    }
    while (!Stk.empty() && Stk.top().second == 0) Stk.pop();
    num ^= 1;
    i = j;
  }
  cout << maior << '\n';
  for (int i = 1; i <= maior; i++) {
    for (int j = 0; j < P[i].size(); j++) cout << P[i][j] << " ";
    cout << '\n';
  }
  return 0;
}
