#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
char s[N];
int id;
string name[N];
int dis[N];
vector<int> g[N];
vector<int> lst[N];
int getitem(int &t) {
  if (s[t] == 0) return 0;
  int nw = ++id;
  for (; s[t] != ',' && s[t] != 0; ++t) {
    name[nw] += s[t];
  }
  if (s[t] == ',') ++t;
  int c = 0;
  for (; s[t] != ',' && s[t] != 0; ++t) {
    c = c * 10 + s[t] - '0';
  }
  if (s[t] == ',') ++t;
  for (int i = 0; i < c; ++i) {
    g[nw].push_back(getitem(t));
  }
  return nw;
}
void bfs(int src) {
  queue<int> q;
  q.push(src);
  dis[src] = 0;
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    for (auto i : g[t]) {
      dis[i] = dis[t] + 1;
      q.push(i);
    }
  }
}
int main() {
  scanf("%s", s);
  int t = 0;
  int x;
  vector<int> v;
  while (x = getitem(t)) {
    v.push_back(x);
  }
  for (auto x : v) bfs(x);
  int mx = 0;
  for (int i = 1; i <= id; ++i) {
    mx = max(mx, dis[i]);
    lst[dis[i]].push_back(i);
  }
  printf("%d\n", mx + 1);
  for (int i = 0; i <= mx; ++i) {
    for (int j = 0; j < ((int)lst[i].size()); ++j) {
      printf("%s%c", name[lst[i][j]].c_str(),
             " \n"[j == ((int)lst[i].size()) - 1]);
    }
  }
  return 0;
}
