#include <bits/stdc++.h>
using namespace std;
string n;
vector<string> sol[500000];
int main() {
  cin >> n;
  vector<string> nomi;
  vector<int> figli;
  int temp = 0, cont = 1;
  string temp2;
  bool num = true;
  for (int i = n.size() - 1; i >= 0; i--) {
    if (n[i] == ',') {
      if (num)
        figli.push_back(temp);
      else {
        reverse(temp2.begin(), temp2.end());
        nomi.push_back(temp2);
      }
      num ^= true;
      temp = 0;
      temp2.clear();
      cont = 1;
    } else {
      if (num) {
        temp += (n[i] - '0') * cont;
        cont *= 10;
      } else {
        temp2.push_back(n[i]);
      }
    }
  }
  reverse(temp2.begin(), temp2.end());
  nomi.push_back(temp2);
  int cont2 = 0;
  vector<int> tree;
  int sol2 = 0;
  for (int i = nomi.size() - 1; i >= 0; i--) {
    if (tree.empty()) {
      sol[cont2].push_back(nomi[i]);
      cont2++;
      sol2 = max(sol2, cont2);
      tree.push_back(figli[i]);
    } else {
      if (tree[tree.size() - 1] > 0) {
        sol[cont2].push_back(nomi[i]);
        cont2++;
        sol2 = max(sol2, cont2);
        tree[tree.size() - 1]--;
        tree.push_back(figli[i]);
      } else {
        int k = tree.size();
        while (k != 0 && tree[k - 1] == 0) {
          tree.erase(tree.begin() + k - 1);
          k--;
          cont2--;
        }
        sol[cont2].push_back(nomi[i]);
        cont2++;
        if (tree.size() > 0) tree[tree.size() - 1]--;
        tree.push_back(figli[i]);
      }
    }
  }
  cout << sol2 << endl;
  for (int i = 0; i < 500000; i++) {
    if (sol[i].size() == 0)
      break;
    else {
      for (int j = 0; j < sol[i].size(); j++) {
        cout << sol[i][j] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}
