#include <bits/stdc++.h>
using namespace std;
const int lenmax = 1e6 + 6;
int max_depth = 0;
char s[lenmax];
struct T;
vector<T*> w[lenmax];
struct T {
  vector<T*> children;
  string s_;
  T(string s) : s_(s) {}
  T() : T("") {}
  int add(char* s, int cnt = 0) {
    int i = 0;
    if (!cnt) {
      while (s[i] >= '0' && s[i] <= '9') {
        cnt = cnt * 10 + s[i] - '0';
        i++;
      }
      if (s[i] == ',') i++;
    }
    for (int k = 0; k < cnt; k++) {
      int j = i;
      while (s[i] != ',' && s[i]) {
        i++;
      }
      char prev = s[i];
      s[i] = 0;
      T* son = new T(string(s + j));
      s[i] = prev;
      if (s[i] == ',') i++;
      i += son->add(s + i);
      children.push_back(son);
    }
    if (s[i] == ',') i++;
    return i;
  }
  void df(int depth = 0) {
    max_depth = max(max_depth, depth);
    w[depth].push_back(this);
    for (const auto& ptr : children) {
      ptr->df(depth + 1);
    }
  }
  string str() { return s_; }
};
T* root = new T();
int main() {
  cin >> s;
  char* p = s;
  while (*p) {
    p += root->add(p, 1);
  }
  root->df();
  cout << max_depth << '\n';
  for (int depth = 1; depth <= max_depth; depth++) {
    for (T* q : w[depth]) {
      cout << q->str() << ' ';
    }
    cout << '\n';
  }
  return 0;
}
