Alex was programming while Valentina (his toddler daughter) got there and started asking many questions about the round brackets (or parenthesis) in the code. He explained her a bit and when she got it he gave her a task in order to finish his code on time.

For the purpose of this problem we consider only strings consisting of opening and closing round brackets, that is characters '(' and ')'.

The sequence of brackets is called correct if: 

  1. it's empty; 
  2. it's a correct sequence of brackets, enclosed in a pair of opening and closing brackets; 
  3. it's a concatenation of two correct sequences of brackets. 



For example, the sequences "()()" and "((()))(())" are correct, while ")(()", "(((((" and "())" are not.

Alex took a piece of paper, wrote a string s consisting of brackets and asked Valentina to count the number of distinct non-empty substrings of s that are correct sequences of brackets. In other words, her task is to count the number of non-empty correct sequences of brackets that occur in a string s as a substring (don't mix up with subsequences).

When Valentina finished the task, Alex noticed he doesn't know the answer. Help him don't loose face in front of Valentina and solve the problem!

Input

The first line of the input contains an integer n (1 ≤ n ≤ 500 000) — the length of the string s.

The second line contains a string s of length n consisting of only '(' and ')'.

Output

Print the number of distinct non-empty correct sequences that occur in s as substring.

Examples

Input

10
()()()()()


Output

5


Input

7
)(())()


Output

3

Note

In the first sample, there are 5 distinct substrings we should count: "()", "()()", "()()()", "()()()()" and "()()()()()".

In the second sample, there are 3 distinct substrings we should count: "()", "(())" and "(())()".
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long BIG = 1446803456761533460LL;
const int Big = 336860180;
const long long int INF = LONG_LONG_MAX;
long long int gcd(long long int a, long long int b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long int powMod(long long int a, long long int b) {
  long long int n = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      n = (n * (a)) % MOD;
    }
    a = (a * (a)) % MOD;
    b /= 2;
  }
  return n;
}
long long int modularInverse(long long int a) { return powMod(a, MOD - 2); }
stringstream sss;
const long long int maxn = 500010;
const long long int maxnlg = 20;
long long int n;
char s[maxn];
pair<pair<long long int, long long int>, long long int> suf[maxn];
long long int ord[maxnlg][maxn];
long long int lcp[maxn];
long long int val[maxn];
vector<long long int> idxs[maxn * 2];
void MAIN() {
  cin >> n;
  for (long long int i = (0); i < (n); ++i) {
    cin >> s[i];
    ord[0][i] = s[i];
  }
  for (long long int i = (0); i < (maxnlg - 1); ++i) {
    for (long long int j = (0); j < (n); ++j) {
      long long int snd = j + (1 << i);
      suf[j] = {{ord[i][j], snd >= n ? -1 : ord[i][snd]}, j};
    }
    sort(suf, suf + n);
    long long int ii = 0;
    for (long long int j = (0); j < (n); ++j) {
      if (j > 0 && suf[j - 1].first < suf[j].first) ++ii;
      ord[i + 1][suf[j].second] = ii;
    }
  }
  for (long long int i = (0); i < (n - 1); ++i) {
    long long int a = suf[i].second;
    long long int b = suf[i + 1].second;
    for (long long int j = (maxnlg)-1; j >= (0); --j) {
      if (max(a, b) + (1 << j) <= n && ord[j][a] == ord[j][b]) {
        a += (1 << j);
        b += (1 << j);
        lcp[i] += (1 << j);
      }
    }
  }
  long long int c = maxn;
  val[0] = c;
  for (long long int i = (0); i < (n); ++i) {
    if (s[i] == '(') {
      ++c;
    } else {
      --c;
    }
    val[i + 1] = c;
    idxs[c].push_back(i);
  }
  long long int ans = 0;
  long long int lt = 0;
  for (long long int i = (0); i < (n); ++i) {
    long long int si = suf[i].second;
    if (s[si] == ')') continue;
    auto it =
        lower_bound((idxs[val[si] - 1]).begin(), (idxs[val[si] - 1]).end(), si);
    long long int rt = it == idxs[val[si] - 1].end() ? n : *it;
    long long int d =
        lower_bound((idxs[val[si]]).begin(), (idxs[val[si]]).end(), rt) -
        lower_bound((idxs[val[si]]).begin(), (idxs[val[si]]).end(), si + lt);
    ans += max(0LL, d);
    lt = lcp[i];
  }
  cout << (ans) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  sss << R"(
10
()()()()()
7
)(())()
    )";
  MAIN();
  return 0;
}
