#include <bits/stdc++.h>
using namespace std;
const char IO_MODE = 0;
constexpr long long operator"" _K(unsigned long long n) { return 1000 * n; }
constexpr long long operator"" _M(unsigned long long n) { return 1000000 * n; }
void operator"" _print(char const *s, size_t n) { printf("%s\n", s); }
inline long long ReadInt() {
  long long x = 0, s = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') s = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return s * x;
}
inline void WriteInt(long long x) {
  char c[20];
  if (!x) {
    putchar('0');
    return;
  }
  if (x < 0) putchar('-'), x = -x;
  int i = 0;
  while (x > 0) c[++i] = x % 10, x /= 10;
  while (i) putchar(c[i--] + 48);
}
template <typename T>
inline void out(T x) {
  if (IO_MODE & 1)
    WriteInt(x);
  else if (typeid(x) == typeid(int))
    printf("%i", x);
  else if (typeid(x) == typeid(long long))
    printf("%lld", x);
}
template <typename T, typename... Args>
inline void out(T x, Args... args) {
  out(x);
  putc(' ', stdout);
  out(args...);
}
template <typename T>
inline void in(T &x) {
  if (IO_MODE & 2)
    x = ReadInt();
  else if (typeid(x) == typeid(int))
    scanf("%i", &x);
  else if (typeid(x) == typeid(long long))
    scanf("%lld", &x);
}
template <typename T, typename... Args>
inline void in(T &x, Args &...args) {
  in(x);
  in(args...);
}
int aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, mm, nn, oo, pp, qq, rr, ss, tt,
    uu, vv, ww, xx, yy, zz;
int tc;
int n, ans;
char s[1000100];
int P[1000100], S[1000100];
int main() {
  in(n);
  scanf("%s", s + 1);
  int bal = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == '(')
      bal++;
    else
      bal--;
    if (bal < 0) bal = -1000000007;
    P[i] = bal;
  }
  bal = 0;
  for (int i = n; i; i--) {
    if (s[i] == '(')
      bal++;
    else
      bal--;
    if (bal > 0) bal = 1000000007;
    S[i] = bal;
  }
  for (int i = 1; i <= n; i++) {
    if (P[i - 1] < 0 || S[i + 1] > 0) continue;
    int bal = P[i - 1];
    if (s[i] == ')')
      bal++;
    else
      bal--;
    if (bal < 0) continue;
    bal += S[i + 1];
    if (!bal) ans++;
  }
  cout << ans << endl;
}

### 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;
const char IO_MODE = 0;
constexpr long long operator"" _K(unsigned long long n) { return 1000 * n; }
constexpr long long operator"" _M(unsigned long long n) { return 1000000 * n; }
void operator"" _print(char const *s, size_t n) { printf("%s\n", s); }
inline long long ReadInt() {
  long long x = 0, s = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') s = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return s * x;
}
inline void WriteInt(long long x) {
  char c[20];
  if (!x) {
    putchar('0');
    return;
  }
  if (x < 0) putchar('-'), x = -x;
  int i = 0;
  while (x > 0) c[++i] = x % 10, x /= 10;
  while (i) putchar(c[i--] + 48);
}
template <typename T>
inline void out(T x) {
  if (IO_MODE & 1)
    WriteInt(x);
  else if (typeid(x) == typeid(int))
    printf("%i", x);
  else if (typeid(x) == typeid(long long))
    printf("%lld", x);
}
template <typename T, typename... Args>
inline void out(T x, Args... args) {
  out(x);
  putc(' ', stdout);
  out(args...);
}
template <typename T>
inline void in(T &x) {
  if (IO_MODE & 2)
    x = ReadInt();
  else if (typeid(x) == typeid(int))
    scanf("%i", &x);
  else if (typeid(x) == typeid(long long))
    scanf("%lld", &x);
}
template <typename T, typename... Args>
inline void in(T &x, Args &...args) {
  in(x);
  in(args...);
}
int aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, mm, nn, oo, pp, qq, rr, ss, tt,
    uu, vv, ww, xx, yy, zz;
int tc;
int n, ans;
char s[1000100];
int P[1000100], S[1000100];
int main() {
  in(n);
  scanf("%s", s + 1);
  int bal = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == '(')
      bal++;
    else
      bal--;
    if (bal < 0) bal = -1000000007;
    P[i] = bal;
  }
  bal = 0;
  for (int i = n; i; i--) {
    if (s[i] == '(')
      bal++;
    else
      bal--;
    if (bal > 0) bal = 1000000007;
    S[i] = bal;
  }
  for (int i = 1; i <= n; i++) {
    if (P[i - 1] < 0 || S[i + 1] > 0) continue;
    int bal = P[i - 1];
    if (s[i] == ')')
      bal++;
    else
      bal--;
    if (bal < 0) continue;
    bal += S[i + 1];
    if (!bal) ans++;
  }
  cout << ans << endl;
}

```