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 int M = 600010;
char s[M];
int wa[M], wb[M], wv[M], wc[M];
int r[M], sa[M], rak[M], height[M], SIGMA = 0;
int cmp(int *r, int a, int b, int l) {
  return r[a] == r[b] && r[a + l] == r[b + l];
}
void da(int *r, int *sa, int n, int m) {
  int i, j, p, *first = wa, *second = wb, *t;
  for (i = 0; i < m; i++) wc[i] = 0;
  for (i = 0; i < n; i++) wc[first[i] = r[i]]++;
  for (i = 1; i < m; i++) wc[i] += wc[i - 1];
  for (i = n - 1; i >= 0; i--) sa[--wc[first[i]]] = i;
  for (j = 1, p = 1; p < n; j *= 2, m = p) {
    for (p = 0, i = n - j; i < n; i++) second[p++] = i;
    for (i = 0; i < n; i++)
      if (sa[i] >= j) second[p++] = sa[i] - j;
    for (i = 0; i < n; i++) wv[i] = first[second[i]];
    for (i = 0; i < m; i++) wc[i] = 0;
    for (i = 0; i < n; i++) wc[wv[i]]++;
    for (i = 1; i < m; i++) wc[i] += wc[i - 1];
    for (i = n - 1; i >= 0; i--) sa[--wc[wv[i]]] = second[i];
    for (t = first, first = second, second = t, p = 1, first[sa[0]] = 0, i = 1;
         i < n; i++)
      first[sa[i]] = cmp(second, sa[i - 1], sa[i], j) ? p - 1 : p++;
  }
}
void calheight(int *r, int *sa, int n) {
  int i, j, k = 0;
  for (i = 1; i <= n; i++) rak[sa[i]] = i;
  for (i = 0; i < n; height[rak[i++]] = k) {
    for (k ? k-- : 0, j = sa[rak[i] - 1]; r[i + k] == r[j + k]; k++)
      ;
  }
}
struct BIT {
  int tree[M];
  BIT() {}
  void clear() { memset((tree), (0), sizeof(tree)); }
  void update(int idx, int val) {
    while (idx < M) {
      tree[idx] += val;
      idx += idx & (-idx);
    }
  }
  int query(int idx) {
    int sum = 0;
    while (idx > 0) {
      sum += tree[idx];
      idx -= idx & (-idx);
    }
    return sum;
  }
};
char A[M];
stack<int> S;
set<int> _set;
BIT B;
int match[M];
int L[M];
int R[M];
int temp[M];
int len;
int proper(int l, int r) {
  if (r < l) return 0;
  return l == 0 ? B.query(r) : B.query(r) - B.query(l - 1);
}
int calc(int pos, int lenth) {
  int nxt = *_set.upper_bound(pos);
  return proper(pos, min(nxt - 1, pos + lenth - 1));
}
long long function_name_goes_here() {
  int i, j, k;
  long long sum = 0;
  memset((match), (-1), sizeof(match));
  for (i = 0; i < len; i++) {
    if (A[i] == '(')
      S.push(i);
    else {
      if (S.empty() || A[S.top()] == ')')
        _set.insert(i);
      else
        match[S.top()] = i, S.pop();
    }
  }
  while (!S.empty()) _set.insert(S.top()), S.pop();
  for (i = 0; i < len; match[i] == -1 ? i++ : i = match[i] + 1)
    if (match[i] != -1) B.update(match[i], 1);
  for (i = 0; i < len; i++) {
    if (match[i] != -1) {
      int a = calc(i, L[i]), b = calc(i, R[i]);
      sum += b - a;
      _set.insert(match[i]);
      B.update(match[i], -1);
      for (j = i + 1; j < match[i]; match[j] == -1 ? j++ : j = match[j] + 1) {
        B.update(match[j], 1);
      }
    }
  }
  return sum;
}
int main() {
  int i, j, k;
  scanf("%d", &len);
  scanf("%s", A);
  SIGMA = 0;
  for (i = 0; i < len; i++)
    r[i] = A[i], SIGMA = max(SIGMA, r[i]), R[i] = len - i;
  r[len] = 0;
  da(r, sa, len + 1, SIGMA + 1);
  calheight(r, sa, len);
  _set.insert(len);
  L[sa[0]] = 0;
  for (i = 1; i <= len; i++) L[sa[i]] = height[i];
  B.clear();
  cout << function_name_goes_here() << endl;
  return 0;
}
