#include <bits/stdc++.h>
using namespace std;
const int maxn = 1200000;
string input;
vector<int> G[maxn];
string tt[maxn];
bool vis[maxn];
int dep;
vector<string> ans[maxn];
void init() {
  for (int i = 0; i < maxn; i++) {
    G[i].clear();
    tt[i].clear();
    vis[i] = 0;
    dep = 0;
    ans[i].clear();
  }
}
void BFS(int now) {
  queue<pair<int, int> > Q;
  Q.push(make_pair(now, 0));
  while (Q.empty() == false) {
    int now = Q.front().first;
    int np = Q.front().second;
    dep = max(dep, Q.front().second);
    ans[np].push_back(tt[now]);
    Q.pop();
    if (vis[now] == 1) continue;
    vis[now] = 1;
    int sz = G[now].size();
    for (int i = 0; i < sz; i++) {
      int v = G[now][i];
      if (vis[v] == 0) Q.push(make_pair(v, np + 1));
    }
  }
}
int main() {
  while (cin >> input) {
    init();
    int len = input.length();
    int now = 0;
    stack<pair<int, int> > S;
    S.push(make_pair(0, 1000000));
    int i = 0;
    int num = 0;
    while (i < len) {
      int cama = 0;
      string text;
      num++;
      int cnt = 0;
      while (cama != 2) {
        if (cama == 0) {
          if (input[i] == ',') {
            cama++;
            i++;
          } else {
            text.push_back(input[i]);
            i++;
          }
        } else if (cama == 1) {
          if (i >= len || input[i] == ',') {
            cama++;
            i++;
          } else {
            cnt = cnt * 10 + input[i] - '0';
            i++;
          }
        }
      }
      if (cnt == 0) {
        tt[num] = text;
        pair<int, int> tp = S.top();
        S.pop();
        tp.second--;
        G[tp.first].push_back(num);
        if (tp.second != 0) {
          S.push(tp);
        }
        if (S.empty() == false) {
          now = S.top().first;
        } else
          now = 0;
      } else {
        if (S.empty() == false) {
          pair<int, int> tp = S.top();
          S.pop();
          tp.second--;
          if (tp.second != 0) S.push(tp);
        }
        S.push(make_pair(num, cnt));
        tt[num] = text;
        G[now].push_back(num);
        now = num;
      }
    }
    BFS(0);
    cout << dep << endl;
    for (int i = 1; i <= dep; i++) {
      for (int j = 0; j < ans[i].size(); j++) {
        if (j == 0)
          cout << ans[i][j];
        else
          cout << " " << ans[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}
