#include <bits/stdc++.h>
using namespace std;
string st, ss = "", second[1000005];
long long num[2000005], sz = 1, wn, anss;
vector<pair<long long, long long> > g;
vector<long long> v[1000001], start, ans[1000005];
void dfs(long long x, long long dep) {
  ans[dep].push_back(x);
  anss = max(anss, dep);
  for (int i = 0; i < v[x].size(); i++) dfs(v[x][i], dep + 1);
}
int main() {
  cin >> st;
  wn = 1;
  for (int i = 0; i < st.size(); i++) {
    if (st[i] == ',') {
      if (wn == 2) {
        wn = 1;
        reverse(ss.begin(), ss.end());
        long long h = 1;
        for (int j = 0; j < ss.size(); j++) {
          num[sz] += h * (ss[j] - '0');
          h *= 10;
        }
        sz++;
        ss = "";
      } else {
        second[sz] = ss;
        ss = "";
        wn = 2;
      }
    } else {
      ss += st[i];
    }
  }
  reverse(ss.begin(), ss.end());
  long long h = 1;
  for (int j = 0; j < ss.size(); j++) {
    num[sz] += h * (ss[j] - '0');
  }
  for (int i = 1; i <= sz; i++) {
    if (!g.size()) {
      start.push_back(i);
      if (num[i]) g.push_back({i, num[i]});
    } else {
      v[g[g.size() - 1].first].push_back(i);
      g[g.size() - 1].second--;
      while (g.size() && g[g.size() - 1].second == 0) g.pop_back();
      if (num[i]) g.push_back({i, num[i]});
    }
  }
  for (int i = 0; i < start.size(); i++) {
    dfs(start[i], 1LL);
  }
  cout << anss << endl;
  for (int i = 1; i <= anss; i++) {
    for (int j = 0; j < ans[i].size(); j++) cout << second[ans[i][j]] << " ";
    cout << endl;
  }
  return 0;
}
