#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
const long long mod2 = 998244353;
const long double eps = 1e-10;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  if (n % 2) {
    cout << 0 << '\n';
  } else {
    int cnt1 = 0, cnt2 = 0;
    for (int i = (int)(0); i < (int)(n); i++) {
      if (s[i] == '(')
        cnt1++;
      else
        cnt2++;
    }
    if (abs(cnt1 - cnt2) != 2) {
      cout << 0 << '\n';
    } else {
      vector<bool> ok_front(n + 1, true), ok_back(n + 1, true);
      vector<int> cnt_front(n + 1), cnt_back(n + 1);
      for (int i = (int)(0); i < (int)(n); i++) {
        cnt_front[i + 1] = cnt_front[i] + (s[i] == '(' ? 1 : -1);
        ok_front[i + 1] = ok_front[i] && (cnt_front[i + 1] >= 0);
      }
      for (int i = (int)((n)-1); i >= (int)(0); i--) {
        cnt_back[i] = cnt_back[i + 1] + (s[i] == '(' ? 1 : -1);
        ok_back[i] = ok_back[i + 1] && (cnt_back[i] <= 0);
      }
      int ans = 0;
      for (int i = (int)(0); i < (int)(n); i++) {
        if (ok_front[i] && ok_back[i + 1] &&
            cnt_front[i] + cnt_back[i + 1] - (s[i] == '(' ? 1 : -1) == 0)
          ans++;
      }
      cout << ans << '\n';
    }
  }
  return 0;
}

### Prompt

Develop a solution in CPP to the problem described below:

You are given a bracket sequence s consisting of n opening '(' and closing ')' brackets.

A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.

You can change the type of some bracket s_i. It means that if s_i =  ')' then you can change it to '(' and vice versa.

Your task is to calculate the number of positions i such that if you change the type of the i-th bracket, then the resulting bracket sequence becomes regular.

Input

The first line of the input contains one integer n (1 ≤ n ≤ 10^6) — the length of the bracket sequence.

The second line of the input contains the string s consisting of n opening '(' and closing ')' brackets.

Output

Print one integer — the number of positions i such that if you change the type of the i-th bracket, then the resulting bracket sequence becomes regular.

Examples

Input


6
(((())


Output


3


Input


6
()()()


Output


0


Input


1
)


Output


0


Input


8
)))(((((


Output


0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
const long long mod2 = 998244353;
const long double eps = 1e-10;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  if (n % 2) {
    cout << 0 << '\n';
  } else {
    int cnt1 = 0, cnt2 = 0;
    for (int i = (int)(0); i < (int)(n); i++) {
      if (s[i] == '(')
        cnt1++;
      else
        cnt2++;
    }
    if (abs(cnt1 - cnt2) != 2) {
      cout << 0 << '\n';
    } else {
      vector<bool> ok_front(n + 1, true), ok_back(n + 1, true);
      vector<int> cnt_front(n + 1), cnt_back(n + 1);
      for (int i = (int)(0); i < (int)(n); i++) {
        cnt_front[i + 1] = cnt_front[i] + (s[i] == '(' ? 1 : -1);
        ok_front[i + 1] = ok_front[i] && (cnt_front[i + 1] >= 0);
      }
      for (int i = (int)((n)-1); i >= (int)(0); i--) {
        cnt_back[i] = cnt_back[i + 1] + (s[i] == '(' ? 1 : -1);
        ok_back[i] = ok_back[i + 1] && (cnt_back[i] <= 0);
      }
      int ans = 0;
      for (int i = (int)(0); i < (int)(n); i++) {
        if (ok_front[i] && ok_back[i + 1] &&
            cnt_front[i] + cnt_back[i + 1] - (s[i] == '(' ? 1 : -1) == 0)
          ans++;
      }
      cout << ans << '\n';
    }
  }
  return 0;
}

```