4451: Comments 评论

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:2 通过:1

题目描述

      互联网上发布了一篇罕见的文章,但无法对其进行评论。在Polycarp的网站上,每篇文章都有评论提要。
     Polycarp网站上的每条评论都是一个非空字符串,由英文字母的大写和小写字母组成。注释具有树状结构,这意味着除了根注释(最高级别的评论)之外的每个注释都只有一个父注释。
    当Polycarp想要将评论保存到他的硬盘驱动器时,他使用以下格式。他以以下格式撰写每条评论:

  • 首先,写下评论的文本;
  • 之后写入评论的数量,此评论是父评论(即对此评论的回复数量);
  • 之后,将写入此注释作为父注释的注释(这些注释的编写使用相同的算法)。
    此格式的所有元素都用单个逗号分隔。同样,第一级的注释用逗号分隔。例如,如果注释如下所示:
    则第一个注释写为“hello,2,ok,0,bye,0”,第二个注释写为“test,0”,第三个注释写为“one,1,two,2,a,0,b,0”。整个评论提要写成:“hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0”。对于上述指定格式的给定评论源,请以不同的格式打印评论:

  • 首先,打印一个整数 d− 嵌套注释的最大深度;
  • 在那之后打印 D 行,其中的第 i 个对应于嵌套级别 I;
  • 对于第 i 行,按照嵌套级别 i 的注释在 Policarp 的评论源中出现的顺序打印注释,以空格分隔。
    A rare article in the Internet is posted without a possibility to comment it. On a Polycarp's website each article has comments feed.
    Each comment on Polycarp's website is a non-empty string consisting of uppercase and lowercase letters of English alphabet. Comments have tree-like structure, that means each comment except root comments (comments of the highest level) has exactly one parent comment.
    When Polycarp wants to save comments to his hard drive he uses the following format. Each comment he writes in the following format:
  • at first, the text of the comment is written;
  • after that the number of comments is written, for which this comment is a parent comment (i.e. the number of the replies to this comments);
  • after that the comments for which this comment is a parent comment are written (the writing of these comments uses the same algorithm).
    All elements in this format are separated by single comma. Similarly, the comments of the first level are separated by comma.For example, if the comments look like:
then the first comment is written as "hello,2,ok,0,bye,0", the second is written as "test,0", the third comment is written as "one,1,two,2,a,0,b,0". The whole comments feed is written as: "hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0". For a given comments feed in the format specified above print the comments in a different format:
  • at first, print a integer d− the maximum depth of nesting comments;
  • after that print d lines, the i-th of them corresponds to nesting level i;
  • for the i-th row print comments of nesting level i in the order of their appearance in the Policarp's comments feed, separated by space.
Input
The first line contains non-empty comments feed in the described format. It consists of uppercase and lowercase letters of English alphabet, digits and commas.
It is guaranteed that each comment is a non-empty string consisting of uppercase and lowercase English characters. Each of the number of comments is integer (consisting of at least one digit), and either equals 0 or does not contain leading zeros.
The length of the whole string does not exceed 106. It is guaranteed that given structure of comments is valid.
Output
Print comments in a format that is given in the statement. For each level of nesting, comments should be printed in the order they are given in the input.
Examples
Input
hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0
Output
3
hello test one 
ok bye two 
a b 


Input
a,5,A,0,a,0,A,0,a,0,A,0
Output
2
a 
A a A a A 


Input
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
Output
4
A K M 
B F H L N O 
C D G I P 
E J 

Note
The first example is explained in the statements.

输入格式

输入
第一行包含所述格式的非空注释源。它由英文字母,数字和逗号的大写和小写字母组成。
保证每个注释都是由大写和小写英文字符组成的非空字符串。每个注释数都是整数(至少由一个数字组成),要么等于 0,要么不包含前导零。
整个字符串的长度不超过
106.保证给定的注释结构是有效的。

输出格式

输出
以语句中给出的格式打印注释。对于每个嵌套级别,注释应按照输入中给出的顺序打印。
例子
输入
hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0
输出
3
hello test one 
ok bye two 
a b 


输入
a,5,A,0,a,0,A,0,a,0,A,0
输出
2
a 
A a A a A 


输入
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
输出
4
A K M 
B F H L N O 
C D G I P 
E J 

注意
第一个示例在语句中进行了解释。

输入样例 复制

hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0

输出样例 复制

3
hello test one 
ok bye two 
a b