#include <bits/stdc++.h>
using namespace std;
vector<pair<string, int> > v;
string s;
int getnum(string ss) {
  int ret = 0;
  int u = 1;
  for (int i = ss.length() - 1; i >= 0; i--) {
    int x = ss[i] - '0';
    x *= u;
    ret += x;
    u *= 10;
  }
  return ret;
}
bool vis[1000005];
int dep[1000005];
int cnt = 0;
vector<string> vv[1000005];
int mx = 0;
void dfs(int node, int d) {
  dep[node] = d;
  vv[d].push_back(v[node].first);
  mx = max(mx, d);
  vis[node] = 1;
  int num = v[node].second;
  for (int i = 0; i < num; i++) {
    cnt++;
    dfs(cnt, d + 1);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> s;
  bool bla = 0;
  string t, tt;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == ',') {
      if (bla) {
        int x = getnum(tt);
        v.push_back({t, x});
        t = "";
        tt = "";
      }
      bla = !bla;
    } else {
      if (!bla)
        t += s[i];
      else
        tt += s[i];
    }
  }
  v.push_back({t, getnum(tt)});
  for (int i = 0; i < v.size(); i++) {
    if (!vis[i]) cnt = i, dfs(i, 0);
  }
  cout << mx + 1 << endl;
  for (int i = 0; i <= mx; i++) {
    for (auto st : vv[i]) {
      cout << st << " ";
    }
    cout << endl;
  }
  return 0;
}
