#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
string s;
unordered_map<string, int> mp;
unordered_map<string, vector<string> > ans;
vector<string> words;
vector<string> v[N];
unordered_map<string, int> idx;
int d = 0;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> s;
  s += ',';
  string tmp = "", word;
  int i = 0;
  bool f = 0;
  while (i < s.size()) {
    if (s[i] == ',' && f == 0) {
      word = tmp;
      int c = idx[word];
      idx[word]++;
      while (c != 0) {
        word += '0' + (c % 10);
        c /= 10;
      }
      words.push_back(word);
      f = 1;
      tmp = "";
      i++;
      continue;
    }
    if (s[i] == ',' && f == 1) {
      int tmp1 = 0, j = 0;
      reverse(tmp.begin(), tmp.end());
      for (auto x : tmp) {
        tmp1 += pow(10, j) * (x - '0');
        j++;
      }
      mp[word] = tmp1;
      f = 0;
      tmp = "";
      i++;
      continue;
    }
    tmp += s[i];
    i++;
  }
  i = 0;
  vector<string> a;
  while (true) {
    if (a.size() > 0 && mp[a.back()] == 0) {
      v[a.size()].push_back(a.back());
      if (a.size() == 1) {
        a.pop_back();
      } else {
        a.pop_back();
        int c = 0;
        string s = a.back();
        for (int i = s.size() - 1; i >= 0; i--) {
          if (s[i] >= '0' && s[i] <= '9') {
            c += s[i] - '0';
          }
        }
        c--;
        while (c != 0) {
          word += '0' + (c % 10);
          c /= 10;
        }
        mp[s]--;
      }
    } else {
      if (i == words.size()) break;
      string b = words[i];
      a.push_back(b);
      d = max(d, (int)a.size());
      i++;
    }
  }
  cout << d << endl;
  for (int i = 1; i <= d; i++) {
    for (auto x : v[i]) {
      for (int j = 0; j <= x.size(); j++) {
        if (x[j] > '9') cout << x[j];
      }
      cout << " ";
    }
    cout << endl;
  }
}
