#include <bits/stdc++.h>
using namespace std;
const int MAX = (int)1e5 + 10;
int n = 0, i = 0;
string text;
vector<vector<int>> g;
vector<string> words;
void parse(int pai) {
  int last = i;
  while (i < text.size() and text[i] != ',') {
    i++;
  }
  string a = text.substr(last, i - last);
  words.push_back(a);
  g.push_back(vector<int>());
  int u = n++;
  g[pai].push_back(u);
  g[u].push_back(pai);
  i++;
  last = i;
  while (i < text.size() and text[i] != ',') {
    i++;
  }
  string aux = text.substr(last, i - last);
  i++;
  int num = stoi(aux);
  while (num--) {
    parse(u);
  }
}
vector<vector<string>> lvl;
void vai() {
  int at = 0;
  lvl.push_back(vector<string>());
  lvl[0].push_back(words[0]);
  at++;
  vector<bool> vist(n, false);
  vist[0] = true;
  queue<int> q1, q2;
  q1.push(0);
  while (q1.size()) {
    lvl.push_back(vector<string>());
    while (q1.size()) {
      int u = q1.front();
      q1.pop();
      for (int e : g[u]) {
        if (vist[e]) continue;
        lvl[at].push_back(words[e]);
        vist[e] = true;
        q2.push(e);
      }
    }
    at++;
    swap(q1, q2);
  }
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin >> text;
  words.push_back("inicio");
  g.push_back(vector<int>());
  n++;
  while (i < text.size()) {
    parse(0);
  }
  vai();
  while (lvl.back().size() == 0) lvl.pop_back();
  cout << lvl.size() - 1 << endl;
  for (int j = 1; j < lvl.size(); j++) {
    for (auto e : lvl[j]) {
      cout << e << " ";
    }
    cout << endl;
  }
  return 0;
}
