#include <bits/stdc++.h>   struct Widget {     std::string name;     long long width, height;     Widget(const std::string& name, long long width, long long height)         : name(name), width(width), height(height) {}     ~Widget() {}     virtual void calculateSize() {}   };   struct Box : public Widget {     int spacing, border;     std::vector<Widget*> children;     Box(const std::string& name) : Widget(name, 0, 0), spacing(0), border(0) {}   };   struct HBox : public Box {     HBox(const std::string& name) : Box(name) {}     virtual void calculateSize() {       if (children.empty()) {         width = 0;         height = 0;         return;       }       if (width == 0 && height == 0) {         for (std::vector<Widget*>::iterator i = children.begin();              i != children.end(); ++i) {           (*i)->calculateSize();           width += (*i)->width;           height = std::max(height, (*i)->height);         }         width += (children.size() - 1) * spacing + 2 * border;         height += 2 * border;       }     }   };   struct VBox : public Box {     VBox(const std::string& name) : Box(name) {}     virtual void calculateSize() {       if (children.empty()) {         width = 0;         height = 0;         return;       }       if (width == 0 && height == 0) {         for (std::vector<Widget*>::iterator i = children.begin();              i != children.end(); ++i) {           (*i)->calculateSize();           width = std::max(width, (*i)->width);           height += (*i)->height;         }         height += (children.size() - 1) * spacing + 2 * border;         width += 2 * border;       }     }   };   int main() {     int n;     std::cin >> n;     std::map<std::string, Widget*> map;     for (int i = 0; i < n; ++i) {       std::string s;       std::cin >> s;       if (s ==  Widget ) {         std::cin >> s;         std::string::size_type lparen = s.find( ( );         std::string name = s.substr(0, lparen);         std::string::size_type comma = s.find( , , lparen + 1);         std::string::size_type rparen = s.find( ) , comma + 1);         int width =             strtol(s.substr(lparen + 1, comma - lparen - 1).c_str(), 0, 10);         int height =             strtol(s.substr(comma + 1, rparen - comma - 1).c_str(), 0, 10);         map[name] = new Widget(name, width, height);       } else if (s ==  VBox ) {         std::cin >> s;         map[s] = new VBox(s);       } else if (s ==  HBox ) {         std::cin >> s;         map[s] = new HBox(s);       } else {         std::string::size_type dot = s.find( . );         std::string::size_type lparen = s.find( ( , dot + 1);         std::string::size_type rparen = s.find( ) , lparen + 1);         std::string name = s.substr(0, dot);         std::string method = s.substr(dot + 1, lparen - dot - 1);         if (method ==  pack ) {           std::string child = s.substr(lparen + 1, rparen - lparen - 1);           static_cast<Box*>(map[name])->children.push_back(map[child]);         } else if (method ==  set_border ) {           int border =               strtol(s.substr(lparen + 1, rparen - lparen - 1).c_str(), 0, 10);           static_cast<Box*>(map[name])->border = border;         } else if (method ==  set_spacing ) {           int spacing =               strtol(s.substr(lparen + 1, rparen - lparen - 1).c_str(), 0, 10);           static_cast<Box*>(map[name])->spacing = spacing;         }       }     }     for (std::map<std::string, Widget*>::iterator i = map.begin(); i != map.end();          ++i) {       Widget* widget = (*i).second;       widget->calculateSize();       std::cout << widget->name <<     << widget->width <<     << widget->height                 << std::endl;     }   }