#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
string s, s1;
int t;
char c;
vector<pair<string, int> > vs;
map<string, vector<string> > G;
bool visit[N];
int pos, curpos = -1, mxlev;
vector<string> lvl[N];
void dfs(int pos, int lev) {
  pair<string, int> z = vs[pos];
  visit[pos] = 1;
  mxlev = max(lev, mxlev);
  lvl[lev].push_back(z.first);
  for (int i = 0; i < z.second; ++i) {
    ++curpos;
    G[z.first].push_back(vs[curpos].first);
    dfs(curpos, lev + 1);
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s;
  s = s + ',';
  int pos = 0;
  while (pos < s.size()) {
    while (s[pos] != ',') {
      s1.push_back(s[pos]);
      ++pos;
    }
    ++pos;
    while (s[pos] != ',') {
      t = t * 10 + (s[pos] - '0');
      ++pos;
    }
    ++pos;
    vs.push_back({s1, t});
    s1 = "";
    t = 0;
  }
  for (int i = 0; i < vs.size(); ++i) {
    if (visit[i]) continue;
    ++curpos;
    dfs(i, 0);
  }
  cout << mxlev + 1 << '\n';
  for (int i = 0; i <= mxlev; ++i) {
    for (int j = 0; j < lvl[i].size(); ++j) cout << lvl[i][j] << ' ';
    cout << '\n';
  }
}
