#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int MAX = 1e6 + 5;
const ll INF = 1e18 + 1;
vector<vector<string> > levels(MAX);
vector<string> comments;
vector<int> children;
int mx = 0, n, ch;
stringstream _s;
string s, x;
int ptr1 = 0, ptr2 = 0;
void print() {
  cout << mx + 1 << "\n";
  for (int i = 0; i <= mx; i++) {
    for (auto str : levels[i]) cout << str << ' ';
    cout << "\n";
  }
}
void dfs(int cur, int cnt) {
  for (int i = 0; i < cur; i++)
    if (ptr1 >= comments.size()) {
      print();
      exit(0);
    } else {
      x = comments[ptr1++];
      ch = children[ptr2++];
      levels[cnt].emplace_back(x);
      mx = max(mx, cnt);
      if (ch) dfs(ch, cnt + 1);
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> s;
  replace(s.begin(), s.end(), ',', ' ');
  _s << s;
  while (true) {
    string temp;
    int c;
    _s >> temp;
    if (!_s) break;
    _s >> c;
    comments.emplace_back(temp);
    children.emplace_back(c);
  }
  dfs(1e6, 0);
  return 0;
}
