#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
namespace debug {
void err() { cout << endl; }
template <template <typename...> class T, typename t, typename... Args>
void err(T<t> a, Args... args) {
  for (auto x : a) cout << x << ' ';
  err(args...);
}
template <typename T, typename... Args>
void err(T a, Args... args) {
  cout << a << ' ';
  err(args...);
}
}  // namespace debug
namespace stdio_input {
void scanf_int() {}
template <typename T, typename... Args>
void scanf_int(T &a, Args &...args) {
  scanf("%d", &a);
  scanf_int(args...);
}
void scanf_ll() {}
template <typename T, typename... Args>
void scanf_ll(T &a, Args &...args) {
  scanf("%lld", &a);
  scanf_ll(args...);
}
void scanf_double() {}
template <typename T, typename... Args>
void scanf_double(T &a, Args &...args) {
  scanf("%lf", &a);
  scanf_double(args...);
}
}  // namespace stdio_input
namespace const_var {
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const int N = 1e6 + 10;
const long double eps = 1e-20;
}  // namespace const_var
using namespace debug;
using namespace stdio_input;
using namespace const_var;
int T = 0;
void testcase() { cout << "Case #" << (++T) << ": "; }
char s[N];
long long suf[N];
inline void work() {
  int n;
  cin >> n >> s;
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == ')') {
      suf[i] = suf[i + 1] - 1;
    } else {
      suf[i] = suf[i + 1] + 1;
    }
    if (suf[i] > 0) suf[i] = inf;
  }
  long long now = 0;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    long long temp = now;
    if (s[i] == '(') {
      ++now;
      --temp;
    } else if (s[i] == ')') {
      --now;
      ++temp;
    }
    if (temp >= 0 && suf[i + 1] == -temp) {
      ans++;
    }
    if (now < 0) now = inf;
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  work();
  return 0;
}

### Prompt

Construct a Cpp code solution to the problem outlined:

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(3)
using namespace std;
namespace debug {
void err() { cout << endl; }
template <template <typename...> class T, typename t, typename... Args>
void err(T<t> a, Args... args) {
  for (auto x : a) cout << x << ' ';
  err(args...);
}
template <typename T, typename... Args>
void err(T a, Args... args) {
  cout << a << ' ';
  err(args...);
}
}  // namespace debug
namespace stdio_input {
void scanf_int() {}
template <typename T, typename... Args>
void scanf_int(T &a, Args &...args) {
  scanf("%d", &a);
  scanf_int(args...);
}
void scanf_ll() {}
template <typename T, typename... Args>
void scanf_ll(T &a, Args &...args) {
  scanf("%lld", &a);
  scanf_ll(args...);
}
void scanf_double() {}
template <typename T, typename... Args>
void scanf_double(T &a, Args &...args) {
  scanf("%lf", &a);
  scanf_double(args...);
}
}  // namespace stdio_input
namespace const_var {
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const int N = 1e6 + 10;
const long double eps = 1e-20;
}  // namespace const_var
using namespace debug;
using namespace stdio_input;
using namespace const_var;
int T = 0;
void testcase() { cout << "Case #" << (++T) << ": "; }
char s[N];
long long suf[N];
inline void work() {
  int n;
  cin >> n >> s;
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == ')') {
      suf[i] = suf[i + 1] - 1;
    } else {
      suf[i] = suf[i + 1] + 1;
    }
    if (suf[i] > 0) suf[i] = inf;
  }
  long long now = 0;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    long long temp = now;
    if (s[i] == '(') {
      ++now;
      --temp;
    } else if (s[i] == ')') {
      --now;
      ++temp;
    }
    if (temp >= 0 && suf[i + 1] == -temp) {
      ans++;
    }
    if (now < 0) now = inf;
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  work();
  return 0;
}

```