#include <bits/stdc++.h>
using namespace std;
struct Node {
  string str;
  int num;
} no[1000005];
char s[1000005];
int cnt = 0, maxn = 0;
bool vis[1000005];
vector<int> ma[1000005];
vector<string> ans[1000005];
void dfs1(int pos, int pre) {
  if (no[pos].num != 0) {
    int x = 0;
    for (int i = pos + 1; i < cnt; i++) {
      if (!vis[i]) {
        x++;
        ma[pos].push_back(i);
        ma[i].push_back(pos);
        dfs1(i, pos);
        vis[pos] = true;
        if (x == no[pos].num) break;
      }
    }
  } else {
    vis[pos] = true;
    return;
  }
}
void dfs2(int pos, int dep) {
  vis[pos] = true;
  maxn = max(maxn, dep);
  ans[dep].push_back(no[pos].str);
  for (int i = 0; i < ma[pos].size(); i++) {
    int to = ma[pos][i];
    if (!vis[to]) dfs2(to, dep + 1);
  }
}
int main() {
  scanf("%s", s);
  int len = strlen(s);
  int num = 0;
  bool f = false;
  string tmp = "";
  for (int i = 0; i < len; i++) {
    if (s[i] == ',') {
      if (!f) {
        no[cnt].str = tmp;
        tmp = "";
        f = true;
      } else {
        no[cnt++].num = num;
        num = 0;
        f = false;
      }
    } else if (s[i] <= '9' && s[i] >= '0') {
      num = num * 10 + s[i] - '0';
    } else {
      tmp += s[i];
    }
  }
  no[cnt++].num = num;
  num = 0;
  for (int i = 0; i < cnt; i++) {
    ma[i].clear();
    ans[i].clear();
  }
  memset(vis, false, sizeof(vis));
  for (int i = 0; i < cnt; i++) {
    if (!vis[i]) dfs1(i, -1);
  }
  memset(vis, false, sizeof(vis));
  for (int i = 0; i < cnt; i++) {
    if (!vis[i]) dfs2(i, 0);
  }
  printf("%d\n", maxn + 1);
  for (int i = 0; i <= maxn; i++) {
    for (int j = 0; j < ans[i].size(); j++) {
      cout << ans[i][j];
      if (j == ans[i].size())
        cout << endl;
      else
        cout << " ";
    }
    cout << endl;
  }
}
