#include using namespace std; void Solve() { int n; cin >> n; vector> g(n); for (int i = 0; i < n; ++i) { for (int _ = 4; _--;) { cin >> ws; if (cin.peek() == 'H') { cin.ignore(); } else { int j; cin >> j; --j; g[i].push_back(j); } } } auto Dfs = [&](auto Dfs, int i, int p) -> void { for (int j : g[i]) { if (j == p) { continue; } cout << '('; Dfs(Dfs, j, i); cout << ')'; } cout << (p == -1 ? "methane" : "methyl"); }; Dfs(Dfs, 0, -1); cout << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); Solve(); }