#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define N #define M #define WATCH(x) cout << (#x) << ": " << (x) << endl #define fWATCH(x, y) cout << x << ": " << y << endl #define tWATCH(x, y, z) cout << x << ": " << y << ", " << z << endl #define INFO(x) cout << "[ " << x << " ]\n" #define nINFO(n, x) cout << "[ " << to_string() << ": " << x << " ]\n" #define SUM(vec, fn) accumulate(vec.begin(), vec.end(), 0, fn) template struct Pair { T1 x; T2 y; }; struct Range { int from; int to; }; using Str = string; template using Vec = vector; using StrVec = vector; using nMap = map; template using xMap = map; // #define FOR(from, to, what) for (auto i = from; i < to; i++) { what(i); } // #define FOR(from, to, from2, to2, what) for (auto j = from; j < to; j++) { for (auto i = from; i < to; i++) { what(i, j); } } typedef long int32; typedef unsigned long uint32; typedef long long ll; typedef unsigned long long uint64; #define toS(x) to_string(x) typedef struct Node { Node * left = nullptr; Node * right = nullptr; Node * parent = nullptr; int value = 1; } Node; int solve(Node * root) { if(root->left != nullptr && root->right != nullptr) { return solve(root->left) * solve(root->right); } if(root->left != nullptr && root->right == nullptr) { root->value = 1 + solve(root->left); } return root->value; } int main() { int n; cin >> n; string brackets; cin >> brackets; char slice[3]; slice[2] = '\0'; int acc = 0; int acc2 = 0; Node * root = new Node(); // building tree for(size_t i = 0; i < brackets.size(); i++) { if(brackets[i] == '(') { if(root->left == nullptr) { root->left = new Node(); root->left->parent = root; root = root->left; } else { root->right = new Node(); root->right->parent = root; root = root->right; } } else if(brackets[i] == ')') { root = root->parent; } } cout << solve(root) << endl; /*for (size_t i = 0; i < brackets.size() - 1; i++) { slice[0] = brackets[i]; slice[1] = brackets[i + 1]; if (!strcmp(slice, "))") || !strcmp(slice, "()")) { ++acc; } else if (!strcmp(slice, ")(")) { if(acc2 == 0) { acc2 = acc; } else { acc2 *= acc; } acc = 0; } } acc2 += acc; cout << acc << '\n';*/ return 0; }