#include using namespace std; using ull = unsigned long long; void solve() { ull n; cin >> n; std::string buffer; buffer.reserve(n*5); char last = 0; ull sum = 0; for (ull i = 0; i < n; i++){ char c; cin >> c; if (last == '(' && c == ')'){ ++sum; } else if (last == ')' && c == ')'){ ++sum; } last = c; } cout << sum << std::endl; } int main() { cin.sync_with_stdio(false); cin.tie(0); solve(); return 0; }