#include <bits/stdc++.h>
using namespace std;
template <class T>
using VV = vector<vector<T>>;
template <class T>
inline T SMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}
template <class T>
inline T SMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class Iter>
void dumpc(Iter begin, Iter end) {
  if (true) {
    for (; begin != end; ++begin) {
      cerr << *begin << ',';
    }
    cerr << endl;
  }
}
const int MAX_N = 1e6 + 1;
string S;
int N;
int cum[MAX_N];
int ok1[MAX_N][2], ok2[MAX_N];
void solve() {
  cum[0] = 0;
  int bal = 0;
  for (int i = 0; i < (N); ++i) {
    bal += S[i] == '(' ? 1 : -1;
    cum[i + 1] = bal;
  }
  ok1[N][0] = ok1[N][1] = 1;
  for (int i = N; i > 0; --i) {
    ok1[i - 1][0] = ok1[i][0] && cum[i] >= 2;
    ok1[i - 1][1] = ok1[i][1] && cum[i] >= -2;
  }
  ok2[0] = true;
  for (int i = 0; i < (N); ++i) ok2[i + 1] = ok2[i] && cum[i + 1] >= 0;
  int res = 0;
  for (int i = 0; i < (N); ++i) {
    if (S[i] == '(') {
      res += (bal - 2 == 0 && ok1[i][0] && ok2[i]);
    } else {
      res += (bal + 2 == 0 && ok1[i][1] && ok2[i]);
    }
  }
  cout << res << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(12) << fixed;
  cin >> N >> S;
  solve();
  return 0;
}

### Prompt

Construct a CPP code solution to the problem outlined:

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;
template <class T>
using VV = vector<vector<T>>;
template <class T>
inline T SMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}
template <class T>
inline T SMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class Iter>
void dumpc(Iter begin, Iter end) {
  if (true) {
    for (; begin != end; ++begin) {
      cerr << *begin << ',';
    }
    cerr << endl;
  }
}
const int MAX_N = 1e6 + 1;
string S;
int N;
int cum[MAX_N];
int ok1[MAX_N][2], ok2[MAX_N];
void solve() {
  cum[0] = 0;
  int bal = 0;
  for (int i = 0; i < (N); ++i) {
    bal += S[i] == '(' ? 1 : -1;
    cum[i + 1] = bal;
  }
  ok1[N][0] = ok1[N][1] = 1;
  for (int i = N; i > 0; --i) {
    ok1[i - 1][0] = ok1[i][0] && cum[i] >= 2;
    ok1[i - 1][1] = ok1[i][1] && cum[i] >= -2;
  }
  ok2[0] = true;
  for (int i = 0; i < (N); ++i) ok2[i + 1] = ok2[i] && cum[i + 1] >= 0;
  int res = 0;
  for (int i = 0; i < (N); ++i) {
    if (S[i] == '(') {
      res += (bal - 2 == 0 && ok1[i][0] && ok2[i]);
    } else {
      res += (bal + 2 == 0 && ok1[i][1] && ok2[i]);
    }
  }
  cout << res << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(12) << fixed;
  cin >> N >> S;
  solve();
  return 0;
}

```