#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("tune=native")
#pragma GCC target("avx")
using namespace std;
const long long mod = 1000000007;
struct SegmentTree {
 private:
  long long n;
  vector<long long> node;

 public:
  SegmentTree(vector<long long> v) {
    long long sz = v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1, INT_MAX);
    for (long long i = 0; i < (long long)(sz); i++) node[i + n - 1] = v[i];
    for (long long i = (long long)(n - 2) - 1; i >= 0; i--)
      node[i] = min(node[2 * i + 1], node[2 * i + 2]);
  }
  void update(long long k, long long x) {
    k += n - 1;
    node[k] = x;
    while (k) {
      k = (k - 1) / 2;
      node[k] = min(node[2 * k + 1], node[2 * k + 2]);
    }
  }
  long long getmin(long long a, long long b, long long k = 0, long long l = 0,
                   long long r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return INT_MAX;
    if (a <= l && r <= b) return node[k];
    return min(getmin(a, b, 2 * k + 1, l, (l + r) / 2),
               getmin(a, b, 2 * k + 2, (l + r) / 2, r));
  }
};
long long n, ret;
string s;
vector<long long> level;
signed main() {
  scanf("%lld", &(n));
  cin >> s;
  level.resize(n + 1);
  for (long long i = 0; i < (long long)(n); i++) {
    level[i + 1] = level[i] + (s[i] == '(' ? 1 : -1);
    if (level[i + 1] < -2) {
      cout << 0 << endl;
      return 0;
    }
  }
  if (abs(level[n]) != 2) {
    cout << 0 << endl;
    return 0;
  }
  char tgt = level[n] < 0 ? ')' : '(';
  long long limit = level[n] < 0 ? -2 : 2;
  SegmentTree st = SegmentTree(level);
  for (long long i = 0; i < (long long)(n); i++) {
    if (s[i] != tgt) continue;
    bool incl = (st.getmin(0, i + 1) >= 0 && st.getmin(i + 1, n + 1) >= limit);
    ret += incl;
  }
  cout << ret << endl;
}

### Prompt

Please formulate a cpp solution to 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>
#pragma GCC optimize("Ofast")
#pragma GCC target("tune=native")
#pragma GCC target("avx")
using namespace std;
const long long mod = 1000000007;
struct SegmentTree {
 private:
  long long n;
  vector<long long> node;

 public:
  SegmentTree(vector<long long> v) {
    long long sz = v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1, INT_MAX);
    for (long long i = 0; i < (long long)(sz); i++) node[i + n - 1] = v[i];
    for (long long i = (long long)(n - 2) - 1; i >= 0; i--)
      node[i] = min(node[2 * i + 1], node[2 * i + 2]);
  }
  void update(long long k, long long x) {
    k += n - 1;
    node[k] = x;
    while (k) {
      k = (k - 1) / 2;
      node[k] = min(node[2 * k + 1], node[2 * k + 2]);
    }
  }
  long long getmin(long long a, long long b, long long k = 0, long long l = 0,
                   long long r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return INT_MAX;
    if (a <= l && r <= b) return node[k];
    return min(getmin(a, b, 2 * k + 1, l, (l + r) / 2),
               getmin(a, b, 2 * k + 2, (l + r) / 2, r));
  }
};
long long n, ret;
string s;
vector<long long> level;
signed main() {
  scanf("%lld", &(n));
  cin >> s;
  level.resize(n + 1);
  for (long long i = 0; i < (long long)(n); i++) {
    level[i + 1] = level[i] + (s[i] == '(' ? 1 : -1);
    if (level[i + 1] < -2) {
      cout << 0 << endl;
      return 0;
    }
  }
  if (abs(level[n]) != 2) {
    cout << 0 << endl;
    return 0;
  }
  char tgt = level[n] < 0 ? ')' : '(';
  long long limit = level[n] < 0 ? -2 : 2;
  SegmentTree st = SegmentTree(level);
  for (long long i = 0; i < (long long)(n); i++) {
    if (s[i] != tgt) continue;
    bool incl = (st.getmin(0, i + 1) >= 0 && st.getmin(i + 1, n + 1) >= limit);
    ret += incl;
  }
  cout << ret << endl;
}

```