#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string line;
  while (getline(cin, line)) {
    map<int, vector<string> > answer;
    line += ',';
    istringstream iss(line);
    string s;
    stack<int> stk;
    string tmp;
    while (getline(iss, s, ',')) {
      getline(iss, tmp, ',');
      int children = stoi(tmp);
      answer[stk.size()].push_back(s);
      if (stk.size() && stk.top() > 0) {
        stk.top()--;
      }
      stk.push(children);
      while (stk.size() && stk.top() <= 0) stk.pop();
    }
    cout << answer.size() << endl;
    for (auto i = 0; i < answer.size(); i++) {
      for (auto &word : answer[i]) cout << word << " ";
      cout << endl;
    }
  }
  return 0;
}
