#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long mod = 1000000007;
const long long linf = 0x3f3f3f3f3f3f3f3f;
const int N = 300100;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int x = 0, y = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(')
      x++;
    else
      y++;
  }
  if (abs(x - y) != 2) {
    cout << "0\n";
    return;
  }
  vector<int> suf(n + 1);
  vector<bool> ok(n + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == ')')
      suf[i] = suf[i + 1] - 1;
    else
      suf[i] = suf[i + 1] + 1;
    ok[i] = ok[i + 1];
    if (suf[i] > 0) ok[i] = 1;
  }
  int ans = 0;
  int cnt = 0;
  int r = (x < y ? 1 : -1);
  for (int i = 0; i < n; i++) {
    if (!ok[i + 1] && cnt + r >= 0 && suf[i + 1] + cnt + r == 0) ans++;
    if (s[i] == '(')
      cnt++;
    else
      cnt--;
    if (cnt < 0) break;
  }
  cout << ans << "\n";
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  ;
  int t_ = 1;
  while (t_--) solve();
  return 0;
}

### Prompt

Please provide a cpp coded solution to the problem described below:

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 inf = 0x3f3f3f3f;
const long long mod = 1000000007;
const long long linf = 0x3f3f3f3f3f3f3f3f;
const int N = 300100;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int x = 0, y = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(')
      x++;
    else
      y++;
  }
  if (abs(x - y) != 2) {
    cout << "0\n";
    return;
  }
  vector<int> suf(n + 1);
  vector<bool> ok(n + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == ')')
      suf[i] = suf[i + 1] - 1;
    else
      suf[i] = suf[i + 1] + 1;
    ok[i] = ok[i + 1];
    if (suf[i] > 0) ok[i] = 1;
  }
  int ans = 0;
  int cnt = 0;
  int r = (x < y ? 1 : -1);
  for (int i = 0; i < n; i++) {
    if (!ok[i + 1] && cnt + r >= 0 && suf[i + 1] + cnt + r == 0) ans++;
    if (s[i] == '(')
      cnt++;
    else
      cnt--;
    if (cnt < 0) break;
  }
  cout << ans << "\n";
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  ;
  int t_ = 1;
  while (t_--) solve();
  return 0;
}

```