#include <bits/stdc++.h>
using namespace std;
struct node {
  long long uno;
  long long unc;
};
node tree[4000005];
void build_tree(long long index, long long a, long long b, string &s) {
  if (a > b) return;
  if (a == b) {
    if (s[a] == '(') {
      tree[index].uno = 1;
      tree[index].unc = 0;
    } else {
      tree[index].uno = 0;
      tree[index].unc = 1;
    }
    return;
  }
  build_tree(index * 2, a, (a + b) / 2, s);
  build_tree(index * 2 + 1, (a + b) / 2 + 1, b, s);
  long long ch = 0;
  ch = min(tree[index * 2].uno, tree[index * 2 + 1].unc);
  tree[index].uno = tree[index * 2].uno + tree[index * 2 + 1].uno - ch;
  tree[index].unc = tree[index * 2].unc + tree[index * 2 + 1].unc - ch;
}
void update_tree(long long index, long long a, long long b, long long i,
                 string &s) {
  if (a == b) {
    if (s[a] == '(') {
      s[a] = ')';
      tree[index].uno = 0;
      tree[index].unc = 1;
    } else {
      s[a] = '(';
      tree[index].uno = 1;
      tree[index].unc = 0;
    }
    return;
  }
  long long mid = (a + b) / 2;
  if (i > mid)
    update_tree(index * 2 + 1, mid + 1, b, i, s);
  else
    update_tree(index * 2, a, mid, i, s);
  long long ch = 0;
  ch = min(tree[index * 2].uno, tree[index * 2 + 1].unc);
  tree[index].uno = tree[index * 2].uno + tree[index * 2 + 1].uno - ch;
  tree[index].unc = tree[index * 2].unc + tree[index * 2 + 1].unc - ch;
}
node query_tree(long long index, long long a, long long b, long long i,
                long long j) {
  node result;
  result.uno = result.unc = INT_MAX;
  if (a > b || a > j || b < i) return result;
  if (a >= i && b <= j) return tree[index];
  node q1 = query_tree(index * 2, a, (a + b) / 2, i, j);
  node q2 = query_tree(index * 2 + 1, (a + b) / 2 + 1, b, i, j);
  long long ch = min(q1.uno, q2.unc);
  node q3;
  q3.uno = q1.uno + q2.uno - ch;
  q3.unc = q1.unc + q2.unc - ch;
  return q3;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long i, j, k, n, t;
  for (i = 0; i <= 4000004; i++) {
    tree[i].uno = 0;
    tree[i].unc = 0;
  }
  cin >> n;
  string s;
  cin >> s;
  build_tree(1, 0, s.length() - 1, s);
  long long q;
  long long ans = 0;
  for (i = 0; i < n; i++) {
    update_tree(1, 0, n - 1, i, s);
    node result = query_tree(1, 0, n - 1, 0, n - 1);
    if (result.uno == 0 && result.unc == 0) ans++;
    update_tree(1, 0, n - 1, i, s);
  }
  cout << ans << endl;
  return 0;
}

### Prompt

In cpp, your task is to solve 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;
struct node {
  long long uno;
  long long unc;
};
node tree[4000005];
void build_tree(long long index, long long a, long long b, string &s) {
  if (a > b) return;
  if (a == b) {
    if (s[a] == '(') {
      tree[index].uno = 1;
      tree[index].unc = 0;
    } else {
      tree[index].uno = 0;
      tree[index].unc = 1;
    }
    return;
  }
  build_tree(index * 2, a, (a + b) / 2, s);
  build_tree(index * 2 + 1, (a + b) / 2 + 1, b, s);
  long long ch = 0;
  ch = min(tree[index * 2].uno, tree[index * 2 + 1].unc);
  tree[index].uno = tree[index * 2].uno + tree[index * 2 + 1].uno - ch;
  tree[index].unc = tree[index * 2].unc + tree[index * 2 + 1].unc - ch;
}
void update_tree(long long index, long long a, long long b, long long i,
                 string &s) {
  if (a == b) {
    if (s[a] == '(') {
      s[a] = ')';
      tree[index].uno = 0;
      tree[index].unc = 1;
    } else {
      s[a] = '(';
      tree[index].uno = 1;
      tree[index].unc = 0;
    }
    return;
  }
  long long mid = (a + b) / 2;
  if (i > mid)
    update_tree(index * 2 + 1, mid + 1, b, i, s);
  else
    update_tree(index * 2, a, mid, i, s);
  long long ch = 0;
  ch = min(tree[index * 2].uno, tree[index * 2 + 1].unc);
  tree[index].uno = tree[index * 2].uno + tree[index * 2 + 1].uno - ch;
  tree[index].unc = tree[index * 2].unc + tree[index * 2 + 1].unc - ch;
}
node query_tree(long long index, long long a, long long b, long long i,
                long long j) {
  node result;
  result.uno = result.unc = INT_MAX;
  if (a > b || a > j || b < i) return result;
  if (a >= i && b <= j) return tree[index];
  node q1 = query_tree(index * 2, a, (a + b) / 2, i, j);
  node q2 = query_tree(index * 2 + 1, (a + b) / 2 + 1, b, i, j);
  long long ch = min(q1.uno, q2.unc);
  node q3;
  q3.uno = q1.uno + q2.uno - ch;
  q3.unc = q1.unc + q2.unc - ch;
  return q3;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long i, j, k, n, t;
  for (i = 0; i <= 4000004; i++) {
    tree[i].uno = 0;
    tree[i].unc = 0;
  }
  cin >> n;
  string s;
  cin >> s;
  build_tree(1, 0, s.length() - 1, s);
  long long q;
  long long ans = 0;
  for (i = 0; i < n; i++) {
    update_tree(1, 0, n - 1, i, s);
    node result = query_tree(1, 0, n - 1, 0, n - 1);
    if (result.uno == 0 && result.unc == 0) ans++;
    update_tree(1, 0, n - 1, i, s);
  }
  cout << ans << endl;
  return 0;
}

```