#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e5 + 10;
struct SuffixArray {
  char S[N];
  int n, SA[N], LCP[N];
  void Init(string T) {
    n = (int)T.size();
    for (int i = 1; i <= n; ++i) S[i] = T[i - 1];
    BuildSA();
    BuildLCP();
  }
  int C[N], L[N], R[N], num[N], pos[N];
  bool mark[N];
  void Init() {
    memset(C, 0, sizeof C);
    for (int i = 1; i <= n; ++i) C[(int)S[i]]++;
    for (int i = 1; i <= 255; ++i) C[i] += C[i - 1];
    for (int i = 1; i <= n; ++i) R[C[(int)S[i]]--] = i;
    for (int i = 1; i <= n; ++i) mark[i] = i == 1 || S[R[i - 1]] != S[R[i]];
  }
  void Sort(int k) {
    for (int i = 1; i <= n; ++i) C[i] = 0;
    for (int i = 1; i <= n; ++i) C[num[L[i]]]++;
    for (int i = 1; i <= n; ++i) C[i] += C[i - 1];
    for (int i = n; i >= 1; --i) R[C[num[L[i]]]--] = L[i];
    for (int i = 1, p = -1; i <= n; ++i) {
      int x = num[(R[i] + k + n - 1) % n + 1];
      mark[i] = p != x || num[R[i - 1]] != num[R[i]];
      p = x;
    }
  }
  void BuildSA() {
    n = n + 1;
    S[n] = 0;
    Init();
    for (int k = 1; k <= n; k <<= 1) {
      for (int i = 1, d = 0; i <= n; ++i) {
        if (mark[i]) d++;
        num[R[i]] = d;
        L[i] = (R[i] - k + n - 1) % n + 1;
      }
      Sort(k);
    }
    n = n - 1;
    for (int i = 0; i <= n; ++i) SA[i] = R[i + 1];
  }
  void BuildLCP() {
    for (int i = 1; i <= n; ++i) pos[SA[i]] = i;
    for (int i = 1, q = 0; i <= n; ++i, q = max(0, q - 1)) {
      int j = SA[pos[i] - 1];
      while (S[i + q] == S[j + q]) q++;
      LCP[pos[i]] = q;
    }
  }
} SA;
int n, a[N][21], lg[N];
char S[N];
vector<int> Z[N * 3];
int GetMin(int l, int r) {
  int k = lg[r - l + 1];
  return min(a[l][k], a[r - (1 << k) + 1][k]);
}
int main() {
  scanf("%d", &n);
  scanf("%s", S + 1);
  SA.Init(string(S + 1, S + 1 + n));
  for (int i = 1; i <= n; ++i) a[i][0] = a[i - 1][0] + (S[i] == '(' ? 1 : -1);
  for (int j = 1; 1 << j <= n; ++j)
    for (int i = 1; i <= n - (1 << j) + 1; ++i)
      a[i][j] = min(a[i][j - 1], a[i + (1 << (j - 1))][j - 1]);
  for (int i = 0; 1 << i <= n; ++i) lg[1 << i] = i;
  for (int i = 1; i <= n; ++i)
    if (lg[i] == 0) lg[i] = lg[i - 1];
  for (int i = 1; i <= n; ++i) Z[a[i][0] + n].push_back(i);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    int p = SA.SA[i];
    int l = p + SA.LCP[i], r = n, f = -1;
    while (l <= r) {
      int m = (l + r) >> 1;
      if (GetMin(p, m) >= a[p - 1][0]) {
        f = m;
        l = m + 1;
      } else
        r = m - 1;
    }
    if (f != -1) {
      int k = a[p - 1][0] + n;
      ans += upper_bound(Z[k].begin(), Z[k].end(), f) -
             lower_bound(Z[k].begin(), Z[k].end(), p + SA.LCP[i]);
    }
  }
  cout << ans;
  return 0;
}
