#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int maxn = 1e4 + 5;
int i, j, l, n, m, y, z;
int t, k, d, q, x;
char s[1000005];
struct app {
  vector<char> ss;
  int dep;
  int n;
  int k;
  int time;
};
vector<app> a;
app tmp;
int cmp(app a, app b) {
  return a.dep < b.dep || (a.dep == b.dep && a.time < b.time);
}
int main() {
  scanf("%s", s);
  x = 0;
  n = strlen(s) - 1;
  d = 1;
  int dep = 1;
  int ans = 1;
  stack<int> st;
  tmp.dep = 1;
  for (int i = 0; i <= n; i++) {
    if (d == 1 && s[i] != ',') {
      tmp.ss.push_back(s[i]);
      tmp.n++;
      continue;
    }
    if (d == 1 && s[i] == ',') {
      d = 2;
      continue;
    }
    if (d == 2 && s[i] != ',') {
      tmp.k = tmp.k * 10 + s[i] - '0';
      continue;
    }
    if ((d == 2 && s[i] == ',')) {
      d = 1;
      tmp.time = i;
      a.push_back(tmp);
      x = tmp.k;
      tmp.n = 0;
      tmp.k = 0;
      tmp.dep = 0;
      tmp.ss.clear();
    }
    if (x == 0 && !st.empty()) {
      while (!st.empty() && st.top() == 1) {
        st.pop();
        dep--;
      }
      if (!st.empty()) st.top()--;
    }
    if (x != 0) {
      st.push(x);
      dep++;
    }
    if (st.empty())
      tmp.dep = 1;
    else
      tmp.dep = dep;
    ans = max(ans, dep);
  }
  tmp.time = n + 1;
  a.push_back(tmp);
  x = tmp.k;
  if (!st.empty())
    if (st.top() == 1) {
      st.pop();
      dep--;
    } else
      st.top()--;
  if (x != 0) {
    st.push(x);
    dep++;
  }
  if (st.empty())
    tmp.dep = 1;
  else
    tmp.dep = dep;
  ans = max(ans, dep);
  sort(a.begin(), a.end(), cmp);
  cout << ans << endl;
  n = a.size() - 1;
  int kk = 1;
  for (int i = 0; i <= n; i++) {
    int nn = a[i].n - 1;
    for (int ii = 0; ii <= nn; ii++) printf("%c", a[i].ss[ii]);
    if (i == n || a[i + 1].dep != kk) {
      printf("\n");
      kk++;
    } else
      printf(" ");
  }
}
