#include <bits/stdc++.h>
#pragma comment(linker, "/stack:640000000")
using namespace std;
const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
const double PI = acos(-1.0);
template <class T>
inline T gcd(T a, T b) {
  return (b) == 0 ? (a) : gcd((b), ((a) % (b)));
}
template <class T>
inline T lcm(T a, T b) {
  return ((a) / gcd((a), (b)) * (b));
}
template <typename T>
string NumberToString(T Number) {
  ostringstream second;
  second << Number;
  return second.str();
}
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
int t, n, m;
stack<pair<string, pair<int, int> > > st;
vector<string> arr[500005];
int dep;
void process(string s, int val) {
  while (!st.empty() && st.top().second.second == 0) st.pop();
  if (st.empty()) {
    st.push(make_pair(s, pair<int, int>(1, val)));
    dep = max(dep, 1);
    arr[1].push_back(s);
    return;
  }
  string par = st.top().first;
  pair<int, int> tmp = st.top().second;
  st.pop();
  tmp.second--;
  st.push(make_pair(par, tmp));
  int lvl = tmp.first + 1;
  dep = max(dep, lvl);
  arr[lvl].push_back(s);
  st.push(make_pair(s, pair<int, int>(lvl, val)));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  while (cin >> s) {
    while (!st.empty()) st.pop();
    dep = -1;
    for (int i = 0; i < (s.size()); i++) {
      string org = "";
      int j;
      for (j = i; j < s.size(); j++) {
        if (s[j] == ',') break;
        org += s[j];
      }
      j++;
      int val = 0;
      for (; j < s.size(); j++) {
        if (s[j] == ',') break;
        val *= 10;
        val += (s[j] - '0');
      }
      process(org, val);
      i = j;
    }
    cout << dep << endl;
    for (int i = 1; i <= (dep); i++) {
      for (int j = 0; j < (arr[i].size()); j++) cout << arr[i][j] << " ";
      cout << endl;
    }
    for (int i = 1; i <= (dep); i++) arr[i].clear();
  }
  return 0;
}
