#include <bits/stdc++.h>
using namespace std;
string s, mark[1000006], p;
vector<int> ad[1000006];
vector<string> depth[1000006];
int c, id = 1, r, cur[1000006], mx;
pair<int, int> pa[1000006];
bool vis[1000006];
void go(int u, int d) {
  depth[d].push_back(mark[u]);
  mx = max(mx, d);
  vis[u] = true;
  for (int i = 0; i < ad[u].size(); i++) {
    int v = ad[u][i];
    if (!vis[v]) {
      go(v, d + 1);
    }
  }
}
int main() {
  cin >> s;
  int sz = s.size();
  p = "";
  for (int i = 0; i < sz; i++) {
    if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) {
      p = "";
      while (i < sz && s[i] != ',') {
        p += s[i];
        i++;
      }
      mark[id++] = p;
    } else if (s[i] >= '0' && s[i] <= '9') {
      r = 0;
      while (i < sz && s[i] != ',') {
        int u = s[i] - '0';
        r += u;
        r *= 10;
        i++;
      }
      r /= 10;
      cur[id - 1] = r;
      pa[c++] = pair<int, int>(id - 1, r);
    }
  }
  stack<pair<int, int> > qu;
  pair<int, int> pre, now;
  for (int i = 0; i < c; i++) {
    if (pa[i].second > 0)
      qu.push(pa[i]);
    else {
      now = pa[i];
      if (qu.empty()) continue;
      pre = qu.top();
      ad[pre.first].push_back(now.first);
      cur[pre.first]--;
      while (cur[pre.first] == 0 && !qu.empty()) {
        qu.pop();
        while (!qu.empty()) {
          now = qu.top();
          if (now.second > 0) {
            ad[now.first].push_back(pre.first);
            cur[now.first]--;
            pre = now;
            break;
          } else {
            qu.pop();
          }
        }
      }
    }
  }
  for (int i = 1; i < id; i++) {
    if (!vis[i]) {
      go(i, 1);
    }
  }
  printf("%d\n", mx);
  for (int i = 1; i < mx + 1; i++) {
    int siz = depth[i].size();
    for (int j = 0; j < siz; j++) {
      cout << depth[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
