#include <bits/stdc++.h>
using namespace std;
char gc() { return getchar(); }
template <class T>
int read(T& ans) {
  ans = 0;
  T f = 1;
  char ch = gc();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    if (ch == EOF) return -1;
    ch = gc();
  }
  while (isdigit(ch)) ans = ans * 10 + ch - '0', ch = gc();
  ans *= f;
  return 1;
}
const int Maxn = 2100000;
const int inf = 0x3f3f3f3f;
int n, a[Maxn], sum, ans;
char s[Maxn];
int main() {
  scanf("%d%s", &n, s + 1);
  for (int i = 1; i <= n; i++) a[i] = s[i] == '(' ? 1 : -1;
  for (int i = 1; i <= n; i++) sum += a[i];
  if (sum != 2 && sum != -2) return 0 * puts("0");
  if (sum == -2) {
    for (int i = 1; i <= n; i++) a[i] *= -1;
    for (int l = 1, r = n; l < r; l++, r--) swap(a[l], a[r]);
  }
  sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += a[i];
    if (a[i] > 0) ans++;
    if (sum < 2) ans = 0;
    if (sum < 0) return 0 * puts("0");
  }
  printf("%d\n", ans);
  return 0;
}

### Prompt

Develop a solution in cpp 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;
char gc() { return getchar(); }
template <class T>
int read(T& ans) {
  ans = 0;
  T f = 1;
  char ch = gc();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    if (ch == EOF) return -1;
    ch = gc();
  }
  while (isdigit(ch)) ans = ans * 10 + ch - '0', ch = gc();
  ans *= f;
  return 1;
}
const int Maxn = 2100000;
const int inf = 0x3f3f3f3f;
int n, a[Maxn], sum, ans;
char s[Maxn];
int main() {
  scanf("%d%s", &n, s + 1);
  for (int i = 1; i <= n; i++) a[i] = s[i] == '(' ? 1 : -1;
  for (int i = 1; i <= n; i++) sum += a[i];
  if (sum != 2 && sum != -2) return 0 * puts("0");
  if (sum == -2) {
    for (int i = 1; i <= n; i++) a[i] *= -1;
    for (int l = 1, r = n; l < r; l++, r--) swap(a[l], a[r]);
  }
  sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += a[i];
    if (a[i] > 0) ans++;
    if (sum < 2) ans = 0;
    if (sum < 0) return 0 * puts("0");
  }
  printf("%d\n", ans);
  return 0;
}

```