#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pr(x) printf("%d\n",x)
#define prl(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
const int N = 1e6+55;
vector< int > root;
vector< int > adj[N];
vector< pair<string, int> > v;
vector<int>level[N];
int lev[N], maxlev;
bool vis[N];
int point;
void dfs(int cur, int c) {
if(cur==v.size()) return;
vis[cur] = 1;
lev[cur] = c;
maxlev = max(maxlev, c);
level[lev[cur]].pb(cur);
for(int i=1 ; i<=v[cur].ss ; i++) {
adj[cur].pb(point);
++point;
dfs(point-1, c+1);
}
}
int main() {
// freopen("Task.in","r",stdin);freopen("Task.out","w",stdout);
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin>>s;
s = s+",";
for(int i=0 ; i<s.size() ; i++) {
string word = "";
int child = 0;
while(s[i]!=',') {
word = word+s[i];
++i;
}
++i;
while(s[i]!=',') {
child = child*10+s[i]-'0';
++i;
}
v.pb(mp(word, child));
}
point = 0;
maxlev = 1;
for(int i=0 ; i<v.size() ; i++) {
if(vis[i]) continue;
point = i+1;
dfs(i, 1);
root.pb(i);
}
cout<<(maxlev)<<"\n";
for(int i=0 ; i<N ; i++) {
if(level[i].size()==0) continue;
for(vector<int>::iterator it=level[i].begin() ; it!=level[i].end() ; it++) cout<<v[*it].ff<<" ";
cout<<("\n");
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgbXAgbWFrZV9wYWlyCiNkZWZpbmUgZmYgZmlyc3QKI2RlZmluZSBzcyBzZWNvbmQKI2RlZmluZSBzYyh4KSBzY2FuZigiJWQiLCZ4KQojZGVmaW5lIHNjbCh4KSBzY2Fu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iAgICAgICAgd2hpbGUoc1tpXSE9JywnKSB7CiAgICAgICAgICAgIHdvcmQgPSB3b3JkK3NbaV07CiAgICAgICAgICAgICsraTsKICAgICAgICB9CiAgICAgICAgKytpOwogICAgICAgIHdoaWxlKHNbaV0hPScsJykgewogICAgICAgICAgICBjaGlsZCA9IGNoaWxkKjEwK3NbaV0tJzAnOwogICAgICAgICAgICArK2k7CiAgICAgICAgfQogICAgICAgIHYucGIobXAod29yZCwgY2hpbGQpKTsKICAgIH0KICAgIHBvaW50ID0gMDsKICAgIG1heGxldiA9IDE7CiAgICBmb3IoaW50IGk9MCA7IGk8di5zaXplKCkgOyBpKyspIHsKICAgICAgICBpZih2aXNbaV0pIGNvbnRpbnVlOwogICAgICAgIHBvaW50ID0gaSsxOwogICAgICAgIGRmcyhpLCAxKTsKICAgICAgICByb290LnBiKGkpOwogICAgfQogICAgY291dDw8KG1heGxldik8PCJcbiI7CiAgICBmb3IoaW50IGk9MCA7IGk8TiA7IGkrKykgewogICAgICAgIGlmKGxldmVsW2ldLnNpemUoKT09MCkgY29udGludWU7CiAgICAgICAgZm9yKHZlY3RvcjxpbnQ+OjppdGVyYXRvciBpdD1sZXZlbFtpXS5iZWdpbigpIDsgaXQhPWxldmVsW2ldLmVuZCgpIDsgaXQrKykgY291dDw8dlsqaXRdLmZmPDwiICI7CiAgICAgICAgY291dDw8KCJcbiIpOwogICAgfQp9
QSwzLEIsMixDLDAsRCwxLEUsMCxGLDEsRywwLEgsMSxJLDEsSiwwLEssMSxMLDAsTSwyLE4sMCxPLDEsUCwwCg==
A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0