{"raw_statement":[{"iden":"statement","content":"Vasya writes his own library for building graphical user interface. Vasya called his creation _VTK_ (_VasyaToolKit_). One of the interesting aspects of this library is that widgets are packed in each other.\n\nA widget is some element of graphical interface. Each widget has width and height, and occupies some rectangle on the screen. Any widget in Vasya's library is of type _Widget_. For simplicity we will identify the widget and its type.\n\nTypes _HBox_ and _VBox_ are derivatives of type _Widget_, so they also are types _Widget_. Widgets _HBox_ and _VBox_ are special. They can store other widgets. Both those widgets can use the _pack()_ method to pack directly in itself some other widget. Widgets of types _HBox_ and _VBox_ can store several other widgets, even several equal widgets — they will simply appear several times. As a result of using the method _pack()_ only the link to the packed widget is saved, that is when the packed widget is changed, its image in the widget, into which it is packed, will also change.\n\nWe shall assume that the widget _a_ is packed in the widget _b_ if there exists a chain of widgets _a_ = _c_1, _c_2, ..., _c__k_ = _b_, _k_ ≥ 2, for which _c__i_ is packed directly to _c__i_ + 1 for any 1 ≤ _i_ < _k_. In Vasya's library the situation when the widget _a_ is packed in the widget _a_ (that is, in itself) is not allowed. If you try to pack the widgets into each other in this manner immediately results in an error.\n\nAlso, the widgets _HBox_ and _VBox_ have parameters _border_ and _spacing_, which are determined by the methods _set_border()_ and _set_spacing()_ respectively. By default both of these options equal 0.\n\n<center>![image](https://espresso.codeforces.com/1771585437bca05b19806f0645d41761fcaa2fe1.png)</center>The picture above shows how the widgets are packed into _HBox_ and _VBox_. At that _HBox_ and _VBox_ automatically change their size depending on the size of packed widgets. As for _HBox_ and _VBox_, they only differ in that in _HBox_ the widgets are packed horizontally and in _VBox_ — vertically. The parameter _spacing_ sets the distance between adjacent widgets, and _border_ — a frame around all packed widgets of the desired width. Packed widgets are placed exactly in the order in which the _pack()_ method was called for them. If within _HBox_ or _VBox_ there are no packed widgets, their sizes are equal to 0 × 0, regardless of the options _border_ and _spacing_.\n\nThe construction of all the widgets is performed using a scripting language _VasyaScript_. The description of the language can be found in the input data.\n\nFor the final verification of the code Vasya asks you to write a program that calculates the sizes of all the widgets on the source code in the language of _VasyaScript_."},{"iden":"input","content":"The first line contains an integer _n_ — the number of instructions (1 ≤ _n_ ≤ 100). Next _n_ lines contain instructions in the language _VasyaScript_ — one instruction per line. There is a list of possible instructions below.\n\n*   \"_Widget \\[name\\](\\[x\\],\\[y\\])_\" — create a new widget _\\[name\\]_ of the type _Widget_ possessing the width of _\\[x\\]_ units and the height of _\\[y\\]_ units.\n*   \"_HBox \\[name\\]_\" — create a new widget _\\[name\\]_ of the type _HBox_.\n*   \"_VBox \\[name\\]_\" — create a new widget _\\[name\\]_ of the type _VBox_.\n*   \"_\\[name1\\].pack(\\[name2\\])_\" — pack the widget _\\[name2\\]_ in the widget _\\[name1\\]_. At that, the widget _\\[name1\\]_ must be of type _HBox_ or _VBox_.\n*   \"_\\[name\\].set_border(\\[x\\])_\" — set for a widget _\\[name\\]_ the _border_ parameter to _\\[x\\]_ units. The widget _\\[name\\]_ must be of type _HBox_ or _VBox_.\n*   \"_\\[name\\].set_spacing(\\[x\\])_\" — set for a widget _\\[name\\]_ the _spacing_ parameter to _\\[x\\]_ units. The widget _\\[name\\]_ must be of type _HBox_ or _VBox_.\n\nAll instructions are written without spaces at the beginning and at the end of the string. The words inside the instruction are separated by exactly one space. There are no spaces directly before the numbers and directly after them.\n\nThe case matters, for example, \"_wiDget x_\" is not a correct instruction. The case of the letters is correct in the input data.\n\nAll names of the widgets consist of lowercase Latin letters and has the length from 1 to 10 characters inclusive. The names of all widgets are pairwise different. All numbers in the script are integers from 0 to 100 inclusive\n\nIt is guaranteed that the above-given script is correct, that is that all the operations with the widgets take place after the widgets are created and no widget is packed in itself. It is guaranteed that the script creates at least one widget."},{"iden":"output","content":"For each widget print on a single line its name, width and height, separated by spaces. The lines must be ordered lexicographically by a widget's name.\n\nPlease, do not use the _%lld_ specificator to read or write 64-bit integers in C++. It is preferred to use _cout_ stream (also you may use _%I64d_ specificator)"},{"iden":"examples","content":"Input\n\n12\nWidget me(50,40)\nVBox grandpa\nHBox father\ngrandpa.pack(father)\nfather.pack(me)\ngrandpa.set_border(10)\ngrandpa.set_spacing(20)\nWidget brother(30,60)\nfather.pack(brother)\nWidget friend(20,60)\nWidget uncle(100,20)\ngrandpa.pack(uncle)\n\nOutput\n\nbrother 30 60\nfather 80 60\nfriend 20 60\ngrandpa 120 120\nme 50 40\nuncle 100 20\n\nInput\n\n15\nWidget pack(10,10)\nHBox dummy\nHBox x\nVBox y\ny.pack(dummy)\ny.set_border(5)\ny.set_spacing(55)\ndummy.set_border(10)\ndummy.set_spacing(20)\nx.set_border(10)\nx.set_spacing(10)\nx.pack(pack)\nx.pack(dummy)\nx.pack(pack)\nx.set_border(0)\n\nOutput\n\ndummy 0 0\npack 10 10\nx 40 10\ny 10 10"},{"iden":"note","content":"In the first sample the widgets are arranged as follows:\n\n<center>![image](https://espresso.codeforces.com/c5f4160ce8761c97145161c137af36b3893f5884.png)</center>"}],"translated_statement":"[{\"iden\":\"statement\",\"content\":\"Vasya 编写了自己的图形用户界面库。他将他的创作命名为 _VTK_ (_VasyaToolKit_)。该库的一个有趣特点是小部件可以相互嵌套。\\n\\n小部件是图形界面的某个元素。每个小部件具有宽度和高度，并占据屏幕上的某个矩形区域。在 Vasya 的库中，任何小部件都是 _Widget_ 类型。为简化起见，我们将小部件与其类型等同看待。\\n\\n类型 _HBox_ 和 _VBox_ 是 _Widget_ 类型的派生类，因此它们也是 _Widget_ 类型。_HBox_ 和 _VBox_ 小部件是特殊的，它们可以存储其他小部件。这两个类型的小部件都可以使用 _pack()_ 方法将其他小部件直接嵌入自身。_HBox_ 和 _VBox_ 类型的小部件可以存储多个其他小部件，甚至可以存储多个相同的部件——它们将简单地重复出现多次。调用 _pack()_ 方法时，仅保存被嵌入小部件的引用，即当被嵌入的小部件发生变化时，它在嵌入它的部件中的显示也会相应变化。\\n\\n我们假设小部件 #cf_span[a] 被嵌入到小部件 #cf_span[b] 中，当且仅当存在一个由小部件 #cf_span[a = c1, c2, ..., ck = b]（#cf_span[k ≥ 2]）组成的链，使得对于任意 #cf_span[1 ≤ i < k]，#cf_span[ci] 直接嵌入到 #cf_span[ci + 1] 中。在 Vasya 的库中，不允许出现小部件 #cf_span[a] 被嵌入到自身（即 #cf_span[a]）的情况。如果尝试以这种方式相互嵌入，将立即导致错误。\\n\\n此外，_HBox_ 和 _VBox_ 小部件具有参数 _border_ 和 _spacing_，分别通过方法 _set_border()_ 和 _set_spacing()_ 设置。默认情况下，这两个参数均为 #cf_span[0]。\\n\\n上图展示了小部件如何嵌入 _HBox_ 和 _VBox_ 中。_HBox_ 和 _VBox_ 会根据所嵌入小部件的尺寸自动调整自身大小。_HBox_ 和 _VBox_ 的唯一区别在于：_HBox_ 中的小部件水平排列，_VBox_ 中的小部件垂直排列。参数 _spacing_ 设置相邻小部件之间的距离，_border_ 设置围绕所有嵌入小部件的边框宽度。小部件按调用 _pack()_ 方法的顺序精确排列。如果 _HBox_ 或 _VBox_ 中没有嵌入任何小部件，则其尺寸为 #cf_span[0 × 0]，无论 _border_ 和 _spacing_ 参数如何设置。\",},{\"iden\":\"input\",\"content\":\"第一行包含一个整数 #cf_span[n] —— 指令数量（#cf_span[1 ≤ n ≤ 100]）。接下来的 #cf_span[n] 行包含用 _VasyaScript_ 语言书写的指令，每行一条。以下是可能的指令列表：\\n\\n\\\"_Widget [name]([x],[y])_\\\" —— 创建一个类型为 _Widget_ 的新小部件 _[name]_，其宽度为 _[x]_ 单位，高度为 _[y]_ 单位。\\n\\n\\\"_HBox [name]_\\\" —— 创建一个类型为 _HBox_ 的新小部件 _[name]_。\\n\\n\\\"_VBox [name]_\\\" —— 创建一个类型为 _VBox_ 的新小部件 _[name]_。\\n\\n\\\"_[name1].pack([name2])_\\\" —— 将小部件 _[name2]_ 嵌入到小部件 _[name1]_ 中。此时，小部件 _[name1]_ 必须是 _HBox_ 或 _VBox_ 类型。\\n\\n\\\"_[name].set_border([x])_\\\" —— 将小部件 _[name]_ 的 _border_ 参数设置为 _[x]_ 单位。小部件 _[name]_ 必须是 _HBox_ 或 _VBox_ 类型。\\n\\n\\\"_[name].set_spacing([x])_\\\" —— 将小部件 _[name]_ 的 _spacing_ 参数设置为 _[x]_ 单位。小部件 _[name]_ 必须是 _HBox_ 或 _VBox_ 类型。\\n\\n所有指令在字符串开头和结尾均无空格。指令内部的单词之间恰好用一个空格分隔。数字前后均无空格。大小写敏感，例如 \\\"_wiDget x_\\\" 不是合法指令。输入数据中的字母大小写均正确。\\n\\n所有小部件名称均由小写拉丁字母组成，长度为 #cf_span[1] 到 #cf_span[10] 个字符（含）。所有小部件名称互不相同。脚本中的所有数字均为 #cf_span[0] 到 #cf_span[100]（含）之间的整数。\\n\\n保证上述脚本格式正确，即所有对小部件的操作均发生在小部件创建之后，且没有任何小部件被嵌入自身。保证脚本至少创建了一个小部件。\",},{\"iden\":\"output\",\"content\":\"对每个小部件，单独一行输出其名称、宽度和高度，以空格分隔。行必须按小部件名称的字典序排列。请勿在 C++ 中使用 _%lld_ 标识符读写 64 位整数。建议使用 _cout_ 流（也可使用 _%I64d_ 标识符）\",},{\"iden\":\"examples\",\"content\":\"输入12Widget me(50,40)VBox grandpaHBox fathergrandpa.pack(father)father.pack(me)grandpa.set_border(10)grandpa.set_spacing(20)Widget brother(30,60)father.pack(brother)Widget friend(20,60)Widget uncle(100,20)grandpa.pack(uncle)输出brother 30 60father 80 60friend 20 60grandpa 120 120me 50 40uncle 100 20输入15Widget pack(10,10)HBox dummyHBox xVBox yy.pack(dummy)y.set_border(5)y.set_spacing(55)dummy.set_border(10)dummy.set_spacing(20)x.set_border(10)x.set_spacing(10)x.pack(pack)x.pack(dummy)x.pack(pack)x.set_border(0)输出dummy 0 0pack 10 10x 40 10y 10 10\",},{\"iden\":\"note\",\"content\":\"在第一个样例中，小部件的排列如下：  \"}]","sample_group":[],"show_order":[],"formal_statement":"**Definitions:**\n\n- Let $ W $ be the set of all widgets.\n- Each widget $ w \\in W $ has attributes:  \n  - $ \\text{type}(w) \\in \\{ \\text{Widget}, \\text{HBox}, \\text{VBox} \\} $  \n  - $ \\text{width}(w), \\text{height}(w) \\in \\mathbb{Z}_{\\geq 0} $  \n  - $ \\text{border}(w) \\in \\mathbb{Z}_{\\geq 0} $ (default: 0)  \n  - $ \\text{spacing}(w) \\in \\mathbb{Z}_{\\geq 0} $ (default: 0)  \n  - $ \\text{children}(w) \\subseteq W $, ordered list of directly packed widgets (empty if none)\n\n- For $ w \\in \\{ \\text{HBox}, \\text{VBox} \\} $:  \n  - If $ \\text{children}(w) = \\emptyset $, then $ \\text{width}(w) = 0 $, $ \\text{height}(w) = 0 $  \n  - Else:  \n    - If $ \\text{type}(w) = \\text{HBox} $:  \n      $$\n      \\text{width}(w) = \\sum_{c \\in \\text{children}(w)} \\text{width}(c) + \\max(0, |\\text{children}(w)| - 1) \\cdot \\text{spacing}(w) + 2 \\cdot \\text{border}(w)\n      $$  \n      $$\n      \\text{height}(w) = \\max_{c \\in \\text{children}(w)} \\text{height}(c) + 2 \\cdot \\text{border}(w)\n      $$  \n    - If $ \\text{type}(w) = \\text{VBox} $:  \n      $$\n      \\text{width}(w) = \\max_{c \\in \\text{children}(w)} \\text{width}(c) + 2 \\cdot \\text{border}(w)\n      $$  \n      $$\n      \\text{height}(w) = \\sum_{c \\in \\text{children}(w)} \\text{height}(c) + \\max(0, |\\text{children}(w)| - 1) \\cdot \\text{spacing}(w) + 2 \\cdot \\text{border}(w)\n      $$\n\n- For $ \\text{type}(w) = \\text{Widget} $:  \n  $ \\text{width}(w) $ and $ \\text{height}(w) $ are set explicitly via `set_size(w, w_w, w_h)`\n\n**Given:**\n\n- A sequence of $ n $ instructions, each being one of:\n  1. `create_widget name w_h h_h` → $ \\text{type}(name) = \\text{Widget} $, $ \\text{width}(name) = w_h $, $ \\text{height}(name) = h_h $\n  2. `create_hbox name` → $ \\text{type}(name) = \\text{HBox} $, $ \\text{border}(name) = 0 $, $ \\text{spacing}(name) = 0 $, $ \\text{children}(name) = \\emptyset $\n  3. `create_vbox name` → $ \\text{type}(name) = \\text{VBox} $, $ \\text{border}(name) = 0 $, $ \\text{spacing}(name) = 0 $, $ \\text{children}(name) = \\emptyset $\n  4. `pack parent child` → Append $ child $ to $ \\text{children}(parent) $\n  5. `set_border name b` → $ \\text{border}(name) = b $\n  6. `set_spacing name s` → $ \\text{spacing}(name) = s $\n  7. `set_size name w h` → $ \\text{width}(name) = w $, $ \\text{height}(name) = h $ (only valid for `Widget`)\n\n**Constraints:**\n\n- All widget names are unique, lowercase, length 1–10.\n- No widget is packed into itself (acyclic dependency).\n- Instructions are executed in order; sizes are computed after all instructions.\n\n**Objective:**\n\nCompute final $ (\\text{width}(w), \\text{height}(w)) $ for all $ w \\in W $, then output:\n\n$$\n\\text{For each } w \\in W \\text{ in lexicographic order by name: } \\texttt{[name] [width(w)] [height(w)]}\n$$","simple_statement":null,"has_page_source":false}