#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
map<int, vector<int> > pos;
struct SuffixArray {
  int s[maxn];
  int sa[maxn], rk[maxn], tp[maxn], c[maxn], height[maxn];
  void radixsort(int n, int m) {
    for (int i = 0; i <= m; ++i) c[i] = 0;
    for (int i = 1; i <= n; ++i) ++c[rk[i]];
    for (int i = 1; i <= m; ++i) c[i] += c[i - 1];
    for (int i = n; i >= 1; --i) sa[c[rk[tp[i]]]--] = tp[i];
  }
  void build_sa(int n, int m) {
    for (int i = 1; i <= n; ++i) {
      rk[i] = s[i], tp[i] = i;
    }
    radixsort(n, m);
    for (int k = 1; k <= n; k <<= 1) {
      int p = 0;
      for (int i = n - k + 1; i <= n; ++i) tp[++p] = i;
      for (int i = 1; i <= n; ++i) {
        if (sa[i] > k) tp[++p] = sa[i] - k;
      }
      radixsort(n, m);
      std::swap(rk, tp);
      p = rk[sa[1]] = 1;
      for (int i = 2; i <= n; ++i) {
        rk[sa[i]] =
            (tp[sa[i]] == tp[sa[i - 1]] && tp[sa[i] + k] == tp[sa[i - 1] + k])
                ? p
                : ++p;
      }
      if (p >= n) break;
      m = p;
    }
    int k = 0;
    for (int i = 1; i <= n; ++i) {
      if (k) --k;
      int j = sa[rk[i] - 1];
      while (i + k <= n && j + k <= n && s[i + k] == s[j + k]) ++k;
      height[rk[i]] = k;
    }
  }
} sa;
char s[maxn];
int sum[maxn];
int dp[maxn][24];
void init_rmq(int n, int a[]) {
  for (int i = 1; i <= n; ++i) dp[i][0] = a[i];
  for (int j = 1; (1 << j) <= n; ++j) {
    for (int i = 1; i + (1 << j) - 1 <= n; ++i) {
      dp[i][j] = min(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
    }
  }
}
inline int rmq(int l, int r) {
  int k = 31 - __builtin_clz(r - l + 1);
  return min(dp[l][k], dp[r - (1 << k) + 1][k]);
}
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; ++i) {
    if (s[i] == '(')
      sum[i] = 1, sa.s[i] = 1;
    else
      sum[i] = -1, sa.s[i] = 2;
  }
  sa.build_sa(n, 3);
  for (int i = 1; i <= n; ++i) sum[i] += sum[i - 1];
  for (int i = 1; i <= n; ++i) pos[sum[i]].push_back(i);
  init_rmq(n, sum);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    int x = sa.sa[i];
    if (sa.s[x] == 2) continue;
    int ed = x + sa.height[i];
    int l = ed, r = n, res = l;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (rmq(x, mid) >= sum[x - 1]) {
        res = mid, l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    auto &vec = pos[sum[x - 1]];
    ans += upper_bound(vec.begin(), vec.end(), r) -
           lower_bound(vec.begin(), vec.end(), ed);
  }
  printf("%lld\n", ans);
  return 0;
}
