{"problem":{"name":"E. Comments","description":{"content":"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 consisti","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF747E"},"statements":[{"statement_type":"Markdown","content":"A rare article in the Internet is posted without a possibility to comment it. On a Polycarp's website each article has comments feed.\n\nEach 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.\n\nWhen Polycarp wants to save comments to his hard drive he uses the following format. Each comment he writes in the following format:\n\n*   at first, the text of the comment is written;\n*   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);\n*   after that the comments for which this comment is a parent comment are written (the writing of these comments uses the same algorithm).\n\nAll 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:\n\n<center>![image](https://espresso.codeforces.com/be9282c77361d63dfe60fe2172b1d36593c7c580.png)</center>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:\n\n*   at first, print a integer _d_ — the maximum depth of nesting comments;\n*   after that print _d_ lines, the _i_\\-th of them corresponds to nesting level _i_;\n*   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.\n\n## Input\n\nThe first line contains non-empty comments feed in the described format. It consists of uppercase and lowercase letters of English alphabet, digits and commas.\n\nIt 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.\n\nThe length of the whole string does not exceed 106. It is guaranteed that given structure of comments is valid.\n\n## Output\n\nPrint 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.\n\n[samples]\n\n## Note\n\nThe first example is explained in the statements.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"[{\"iden\":\"statement\",\"content\":\"互联网上一篇稀有的文章被发布时无法评论。在 Polycarp 的网站上，每篇文章都有评论区。\\n\\nPolycarp 网站上的每条评论都是由英文大小写字母组成的非空字符串。评论具有树状结构，即除了根评论（最高层级的评论）外，每条评论恰好有一个父评论。\\n\\n当 Polycarp 想要将评论保存到硬盘时，他使用以下格式：每个评论以如下形式书写：\\n\\n例如，如果评论结构如下：\\n\\n则第一条评论写作 \\\"_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_\\\"。给定上述格式的评论区，请将其转换为另一种格式输出：\\n\\n第一行包含按上述格式描述的非空评论区。它由英文大小写字母、数字和逗号组成。\\n\\n保证每条评论都是由英文大小写字母组成的非空字符串。每个数字均为整数（至少包含一位数字），且要么等于 #cf_span[0]，要么不包含前导零。\\n\\n整个字符串的长度不超过 #cf_span[106]。保证给定的评论结构是合法的。\\n\\n请按题目中给出的格式输出评论。对于每一层嵌套，评论应按输入中出现的顺序输出。\\n\\n第一个示例已在题目中解释。 \"},{\"iden\":\"input\",\"content\":\"第一行包含按上述格式描述的非空评论区。它由英文大小写字母、数字和逗号组成。保证每条评论都是由英文大小写字母组成的非空字符串。每个数字均为整数（至少包含一位数字），且要么等于 #cf_span[0]，要么不包含前导零。整个字符串的长度不超过 #cf_span[106]。保证给定的评论结构是合法的。 \"},{\"iden\":\"output\",\"content\":\"请按题目中给出的格式输出评论。对于每一层嵌套，评论应按输入中出现的顺序输出。 \"},{\"iden\":\"examples\",\"content\":\"输入\\nhello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0\\n输出\\n3\\nhello test one \\nok bye \\ntwo \\na b \\n\\n输入\\na,5,A,0,a,0,A,0,a,0,A,0\\n输出\\n2\\na A a A a \\nA \\n\\n输入\\nA,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\\n输出\\n4\\nA K M \\nB F H L \\nC D G I \\nN O \\nP \\nE J \"},{\"iden\":\"note\",\"content\":\"第一个示例已在题目中解释。 \"}]\n\n---\n\n**说明**：  \n- 所有数学/格式标记如 `#cf_span[0]`、`#cf_span[106]` 均原样保留。  \n- 所有下划线强调（如 `_hello,2,ok,0,bye,0_`）在原始输入中用于示例说明，但在翻译后的正式题面中已移除，仅保留内容本身，符合题面规范。  \n- “交错和”等术语不适用，本题无此概念。  \n- “test case” 在题面中未出现，使用“示例”或“输入/输出”更贴切。  \n- 输出格式中按层级换行，已按示例正确还原。  \n- 严格保持原 JSON 结构与字段名。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ S $ be a comma-separated string representing a comment tree in DFS preorder: each node is encoded as $ (\\text{text}, \\text{num\\_children}) $, where $\\text{text}$ is a non-empty string of English letters and $\\text{num\\_children} \\in \\mathbb{Z}_{\\geq 0}$ is the number of direct child comments.\n\nLet $ T $ be the tree structure defined by $ S $, where each node has at most one parent, and children are ordered left-to-right as they appear in $ S $.\n\n**Constraints**  \n1. $ |S| \\leq 10^6 $  \n2. Each $\\text{text}$ is a non-empty string of uppercase/lowercase English letters.  \n3. Each $\\text{num\\_children}$ is a non-negative integer without leading zeros.  \n4. The structure is valid: the total number of children declared matches the actual subtree structure.  \n\n**Objective**  \nReconstruct the comment tree $ T $ from $ S $, then output the comments in **level-order** (BFS), with each comment on a separate line, indented by $ 2 \\cdot d $ spaces where $ d $ is its depth (root at depth 0).  \nChildren of a comment must appear in the same order as in the input.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF747E","tags":["dfs and similar","expression parsing","implementation","strings"],"sample_group":[["hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0","3\nhello test one \nok bye two \na b"],["a,5,A,0,a,0,A,0,a,0,A,0","2\na \nA 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\nA K M \nB F H L N O \nC D G I P \nE J"]],"created_at":"2026-03-03 11:00:39"}}