#include <bits/stdc++.h>
using namespace std;
int n, md;
string s;
vector<string> nms[1000006];
stack<pair<string, int> > stk;
int main() {
  ios::sync_with_stdio(false);
  cin >> s;
  s += ',';
  int n = s.size();
  string p = "";
  int num = 0;
  int fr = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] != ',' && fr == 0) p += s[i];
    if (s[i] != ',' && fr == 1) num = num * 10 + (s[i] - '0');
    if (s[i] == ',' && fr == 0) {
      fr = 1;
      continue;
    }
    if (s[i] == ',' && fr == 1) {
      fr = 0;
      int x = stk.size() + 1;
      md = max(md, x);
      nms[x].push_back(p);
      stk.push(make_pair(p, num));
      while (!stk.empty()) {
        pair<string, int> pp = stk.top();
        stk.pop();
        if (pp.second == 0) {
          if (stk.empty()) break;
          pair<string, int> qq = stk.top();
          stk.pop();
          qq.second--;
          stk.push(qq);
        } else {
          stk.push(pp);
          break;
        }
      }
      p = "";
      num = 0;
    }
  }
  cout << md << "\n";
  for (int i = 1; i <= md; i++) {
    for (int j = 0; j < nms[i].size(); j++) cout << nms[i][j] << " ";
    cout << "\n";
  }
}
