#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000 + 10;
const int M = 4 * N;
long long tree[M];
void build(int node, int a, int b, long long arr[]) {
  if (a > b) return;
  if (a == b) {
    tree[node] = arr[a];
    return;
  }
  int mid = (a + b) / 2;
  build(2 * node, a, mid, arr);
  build(2 * node + 1, mid + 1, b, arr);
  tree[node] = min(tree[2 * node], tree[2 * node + 1]);
}
int query(int node, int a, int b, int i, int j) {
  if (a > b || i > b || a > j) return 1e7;
  if (a >= i && j >= b) return tree[node];
  int mid = (a + b) / 2;
  int q1 = query(2 * node, a, mid, i, j);
  int q2 = query(2 * node + 1, mid + 1, b, i, j);
  return min(q1, q2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  long long arr[n], suff[n], pref[n];
  for (int i = 0; i < n; i++) {
    arr[i] = (s[i] == '(' ? 1 : -1);
  }
  for (int i = 0, j = n - 1; i < n; i++, j--) {
    if (i) {
      pref[i] = pref[i - 1] + arr[i];
      suff[j] = suff[j + 1] + arr[j];
    } else {
      pref[i] = arr[i];
      suff[j] = arr[j];
    }
  }
  build(1, 0, n - 1, pref);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(') {
      int pre = 0;
      if (i > 0) pre = query(1, 0, n - 1, 0, i - 1);
      int suf = query(1, 0, n - 1, i, n - 1);
      if (pre >= 0 && suf >= 2) {
        if (pref[n - 1] == 2) ans++;
      }
    } else {
      int pre = 0;
      if (i > 0) pre = query(1, 0, n - 1, 0, i - 1);
      int suf = query(1, 0, n - 1, i, n - 1);
      if (pre >= 0 && suf >= -2) {
        if (pref[n - 1] == -2) ans++;
      }
    }
  }
  cout << ans;
  return 0;
}

### Prompt

Your challenge is to write 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>
using namespace std;
const int N = 1000 * 1000 + 10;
const int M = 4 * N;
long long tree[M];
void build(int node, int a, int b, long long arr[]) {
  if (a > b) return;
  if (a == b) {
    tree[node] = arr[a];
    return;
  }
  int mid = (a + b) / 2;
  build(2 * node, a, mid, arr);
  build(2 * node + 1, mid + 1, b, arr);
  tree[node] = min(tree[2 * node], tree[2 * node + 1]);
}
int query(int node, int a, int b, int i, int j) {
  if (a > b || i > b || a > j) return 1e7;
  if (a >= i && j >= b) return tree[node];
  int mid = (a + b) / 2;
  int q1 = query(2 * node, a, mid, i, j);
  int q2 = query(2 * node + 1, mid + 1, b, i, j);
  return min(q1, q2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  long long arr[n], suff[n], pref[n];
  for (int i = 0; i < n; i++) {
    arr[i] = (s[i] == '(' ? 1 : -1);
  }
  for (int i = 0, j = n - 1; i < n; i++, j--) {
    if (i) {
      pref[i] = pref[i - 1] + arr[i];
      suff[j] = suff[j + 1] + arr[j];
    } else {
      pref[i] = arr[i];
      suff[j] = arr[j];
    }
  }
  build(1, 0, n - 1, pref);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(') {
      int pre = 0;
      if (i > 0) pre = query(1, 0, n - 1, 0, i - 1);
      int suf = query(1, 0, n - 1, i, n - 1);
      if (pre >= 0 && suf >= 2) {
        if (pref[n - 1] == 2) ans++;
      }
    } else {
      int pre = 0;
      if (i > 0) pre = query(1, 0, n - 1, 0, i - 1);
      int suf = query(1, 0, n - 1, i, n - 1);
      if (pre >= 0 && suf >= -2) {
        if (pref[n - 1] == -2) ans++;
      }
    }
  }
  cout << ans;
  return 0;
}

```