#include <bits/stdc++.h>
using namespace std;
int min(int a, int b) {
  if (a < b) return a;
  return b;
}
int getMin(vector<int>& f, int pos) {
  int res = INT_MAX;
  for (int i = pos; i >= 0; i = (i & (i + 1)) - 1) res = min(res, f[i]);
  return res;
}
void update(vector<int>& f, int pos, int val) {
  for (int i = pos; i < f.size(); i = (i | (i + 1))) f[i] = min(f[i], val);
}
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> bal(n, 0);
  vector<int> m(n, INT_MAX);
  int cBal = 0;
  int nIndex = INT_MAX - 1;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(')
      cBal++;
    else
      cBal--;
    if (cBal < 0 && nIndex == INT_MAX - 1) nIndex = i;
    bal[i] = cBal;
  }
  for (int i = n - 1; i >= 0; i--) update(m, n - 1 - i, bal[i]);
  if (cBal == 0 || (cBal != 2 && cBal != -2))
    cout << 0;
  else {
    int res = 0;
    int M = 0;
    bool flag;
    for (int i = 0; i < min(nIndex + 1, n); i++) {
      flag = false;
      if (n - i - 2 >= 0)
        M = getMin(m, n - i - 2);
      else
        M = cBal;
      if (s[i] == '(' && bal[i] >= 2 && M >= 2 && cBal == 2)
        res++, flag = true;
      else if (s[i] == ')' && bal[i] >= -2 && M >= -2 && cBal == -2)
        res++, flag = true;
      if (bal[i] < 0 && !flag && i >= nIndex) break;
    }
    cout << res;
  }
  return 0;
}

### Prompt

Create a solution in cpp for the following problem:

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;
int min(int a, int b) {
  if (a < b) return a;
  return b;
}
int getMin(vector<int>& f, int pos) {
  int res = INT_MAX;
  for (int i = pos; i >= 0; i = (i & (i + 1)) - 1) res = min(res, f[i]);
  return res;
}
void update(vector<int>& f, int pos, int val) {
  for (int i = pos; i < f.size(); i = (i | (i + 1))) f[i] = min(f[i], val);
}
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> bal(n, 0);
  vector<int> m(n, INT_MAX);
  int cBal = 0;
  int nIndex = INT_MAX - 1;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(')
      cBal++;
    else
      cBal--;
    if (cBal < 0 && nIndex == INT_MAX - 1) nIndex = i;
    bal[i] = cBal;
  }
  for (int i = n - 1; i >= 0; i--) update(m, n - 1 - i, bal[i]);
  if (cBal == 0 || (cBal != 2 && cBal != -2))
    cout << 0;
  else {
    int res = 0;
    int M = 0;
    bool flag;
    for (int i = 0; i < min(nIndex + 1, n); i++) {
      flag = false;
      if (n - i - 2 >= 0)
        M = getMin(m, n - i - 2);
      else
        M = cBal;
      if (s[i] == '(' && bal[i] >= 2 && M >= 2 && cBal == 2)
        res++, flag = true;
      else if (s[i] == ')' && bal[i] >= -2 && M >= -2 && cBal == -2)
        res++, flag = true;
      if (bal[i] < 0 && !flag && i >= nIndex) break;
    }
    cout << res;
  }
  return 0;
}

```