#include #include using namespace std; int main(){ int numberOfTests = 6; // for (int j = 0; j < numberOfTests; ++j) { int n, result = 0; char current, prev; cin >> n; // for (int i = 0; i < n; ++i) { // cin >> current; // if(i != 0) { //first // if(current == '(' && prev == ')') { // + // // } else if (current == ')' && prev == '(') { // 1 // result += 1; // } else if (current == ')' && prev == ')') { // + 1 // result += 1; // } // } // prev = current; // } stack s; bool first = true; char next; char t; for (int i = 0; i < n; ++i) { cin >> t; s.push(t); } while (!s.empty()) { current = s.top(); s.pop(); if (first) { first = false; } else { if(next == '(' && current == ')') { // + } else if (next == ')' && current == '(' ) { result+=1; } else if (next == ')' && current == ')') { result+=1; } } next = current; } cout << result << endl; // } return 0; }