#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 500;
int n, w[N], ra[N * 2], Ra[N], sa[N], pos[N], lg2[N], mn[N][20], sum[N], h[N];
vector<int> mp[N * 2];
char s[N];
void SA() {
  for (int i = 0; i <= n - 1; i++) w[s[i]] = 1;
  for (int i = 1; i <= 255; i++) w[i] += w[i - 1];
  for (int i = 0; i <= n - 1; i++) ra[i] = w[s[i]];
  memset(w, 0, sizeof(w));
  for (int i = 0; i <= n - 1; i++) w[ra[i]]++;
  for (int i = 1; i <= n; i++) w[i] += w[i - 1];
  for (int i = 0; i <= n - 1; i++) sa[w[ra[i]]--] = i;
  for (int k = 1; k < n; k <<= 1) {
    for (int i = n - k; i <= n - 1; i++) pos[++w[ra[i]]] = i;
    for (int i = 1; i <= n; i++)
      if (sa[i] >= k) pos[++w[ra[sa[i] - k]]] = sa[i] - k;
    Ra[pos[1]] = 1;
    int cnt = 1;
    w[1] = 0;
    for (int i = 2; i <= n; i++) {
      if (ra[pos[i - 1]] != ra[pos[i]] || ra[pos[i - 1] + k] != ra[pos[i] + k])
        w[++cnt] = i - 1;
      Ra[pos[i]] = cnt;
    }
    memcpy(ra, Ra, sizeof(Ra));
    memcpy(sa, pos, sizeof(pos));
  }
  for (int i = 0; i <= n - 1; i++)
    if (ra[i] > 1) {
      int &t = h[ra[i]];
      t = max(0, i ? h[ra[i - 1]] - 1 : 0);
      for (int x = sa[ra[i] - 1];
           x + t < n && i + t < n && s[x + t] == s[i + t]; ++t)
        ;
    }
}
void rmq_init() {
  for (int i = 2; i <= n; i++) lg2[i] = lg2[i - 1] + ((i & -i) == i);
  for (int i = 1; i <= n - 1; i++) mn[i][0] = min(sum[i], sum[i + 1]);
  for (int i = 1; i <= 19; i++)
    for (int j = 1; j <= n - (1 << i); j++)
      mn[j][i] = min(mn[j][i - 1], mn[j + (1 << i - 1)][i - 1]);
}
int rmq(int x, int y) {
  for (int i = 19; i >= 0; i--) {
    if (x + (1 << i) <= n && mn[x][i] >= y) x += 1 << i;
  }
  return x;
}
int main() {
  scanf("%d%s", &n, s);
  SA();
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + (s[i - 1] == '(' ? 1 : -1);
    mp[n + sum[i]].push_back(i);
  }
  rmq_init();
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    if (s[i - 1] == '(') {
      int t = n + sum[i - 1], t2 = rmq(i, sum[i - 1]);
      if (t2 < i) continue;
      int lm = h[ra[i - 1]];
      int t1 = lower_bound(mp[t].begin(), mp[t].end(), i + lm) - mp[t].begin();
      t2 = upper_bound(mp[t].begin(), mp[t].end(), t2) - mp[t].begin() - 1;
      ans += max(0, t2 - t1 + 1);
    }
  printf("%I64d\n", ans);
  return 0;
}
