#include <bits/stdc++.h>
using namespace std;
void pr_init() {}
vector<string> comm;
vector<long long> child;
map<long long, vector<string> > tree;
void parse(string x) {
  for (long long i = 0; i < (long long)x.size(); i++) {
    long long cur = i;
    string temp;
    while (x[cur] != ',') {
      temp.insert(temp.end(), x[cur]);
      cur++;
    }
    cur++;
    comm.emplace_back(temp);
    long long num = 0;
    while (x[cur] >= '0' && x[cur] <= '9') {
      num = 10 * num + (x[cur] - '0');
      cur++;
    }
    child.emplace_back(num);
    i = cur;
  }
}
void display() {
  for (long long i = 0; i < (long long)comm.size(); i++)
    cout << comm[i] << endl;
  for (long long i = 0; i < (long long)child.size(); i++)
    cout << child[i] << endl;
}
void level() {
  stack<long long> st;
  long long car = 0;
  for (long long i = 0; i < (long long)child.size(); i++) {
    tree[st.size()].emplace_back(comm[i]);
    if (child[i] != 0)
      st.push(child[i]);
    else if (st.empty() == false) {
      long long ele = st.top();
      st.pop();
      ele--;
      if (ele == 0)
        car++;
      else
        st.push(ele);
      while (car > 0 && st.empty() == false) {
        long long ele = st.top();
        st.pop();
        ele--;
        if (ele > 0) {
          st.push(ele);
          car = 0;
        } else
          car = 1;
      }
      car = 0;
    }
  }
}
void solve() {
  string s;
  cin >> s;
  parse(s);
  level();
  cout << tree.size() << endl;
  for (auto x : tree) {
    for (auto z : x.second) cout << z << " ";
    cout << endl;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
