/*
Source Code by adityaghosh996
*/
#include<bits/stdc++.h>
#define ll long long int
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
using namespace std;
string name[1000000];
vector<ll> child;
vector<string> level[1000000];
bool vis[1000000];
ll n,pos=0,minuend=0;
inline bool isnum(string s)
{
for(ll i=0;i<s.length();i++)
{
if(!isdigit(s[i]))
return false;
}
return true;
}
inline ll numval(string s)
{
ll val=0;
for(ll i=0;i<s.length();i++)
{
int d=s[i]-'0';
val=val*10+d;
}
return val;
}
inline void dfs(ll curr_level)
{
level[curr_level-minuend].pb(name[pos]);
vis[pos]=true;
ll ch=child[pos];
pos++;
for(ll i=0;i<ch;i++)
{
dfs(curr_level+1);
}
return;
}
int main()
{
ios_base::sync_with_stdio(0);;cin.tie(0);
memset(vis,false,sizeof(vis));
string s;
cin>>s;
vector<string> total;
string temp="";
for(ll i=0;i<s.length();i++)
{
if(s[i]==',')
{
total.pb(temp);
temp="";
}
else
temp=temp+s[i];
}
total.pb(temp);
ll cnt=0;
for(ll i=0;i<total.size();i++)
{
if(isnum(total[i]))
{
child.pb(numval(total[i]));
cnt++;
}
else
{
name[cnt]=total[i];
}
}
n=child.size();
while(pos<n)
{
minuend=pos;
dfs(pos);
}
ll tlev=0;
for(ll i=0;i<1000000;i++)
{
tlev++;
if(level[i].size()==0)
break;
}
cout<<tlev-1<<endl;
for(ll i=0;i<1000000;i++)
{
if(level[i].size()==0)
break;
for(ll j=0;j<level[i].size();j++)
cout<<level[i][j]<<" ";
cout<<endl;
}
return 0;
}
LyoKCVNvdXJjZSBDb2RlIGJ5IGFkaXR5YWdob3NoOTk2CiovCiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nIGludAojZGVmaW5lIHBiKGEpIHB1c2hfYmFjayhhKQojZGVmaW5lIG1wKGEsYikgbWFrZV9wYWlyKGEsYikKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKc3RyaW5nIG5hbWVbMTAwMDAwM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ICAgICAgIHRvdGFsLnBiKHRlbXApOwogICAgICAgICAgICB0ZW1wPSIiOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgICAgIHRlbXA9dGVtcCtzW2ldOwogICAgfQogICAgdG90YWwucGIodGVtcCk7CiAgICBsbCBjbnQ9MDsKICAgIGZvcihsbCBpPTA7aTx0b3RhbC5zaXplKCk7aSsrKQogICAgewogICAgICAgIGlmKGlzbnVtKHRvdGFsW2ldKSkKICAgICAgICB7CiAgICAgICAgICAgIGNoaWxkLnBiKG51bXZhbCh0b3RhbFtpXSkpOwogICAgICAgICAgICBjbnQrKzsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgbmFtZVtjbnRdPXRvdGFsW2ldOwogICAgICAgIH0KICAgIH0KICAgIG49Y2hpbGQuc2l6ZSgpOwogICAgd2hpbGUocG9zPG4pCiAgICB7CiAgICAJbWludWVuZD1wb3M7CgkJZGZzKHBvcyk7Cgl9CglsbCB0bGV2PTA7CiAgICBmb3IobGwgaT0wO2k8MTAwMDAwMDtpKyspCiAgICB7CiAgICAJdGxldisrOwogICAgICAgIGlmKGxldmVsW2ldLnNpemUoKT09MCkKICAgICAgICAgICAgYnJlYWs7CiAgICB9CiAgICBjb3V0PDx0bGV2LTE8PGVuZGw7CiAgICBmb3IobGwgaT0wO2k8MTAwMDAwMDtpKyspCiAgICB7CiAgICAgICAgaWYobGV2ZWxbaV0uc2l6ZSgpPT0wKQogICAgICAgICAgICBicmVhazsKICAgICAgICBmb3IobGwgaj0wO2o8bGV2ZWxbaV0uc2l6ZSgpO2orKykKICAgICAgICAgICAgY291dDw8bGV2ZWxbaV1bal08PCIgIjsKICAgICAgICBjb3V0PDxlbmRsOwogICAgfQogICAgcmV0dXJuIDA7Cn0=