#include <bits/stdc++.h>
const int MX = 5e5 + 23;
const long long MOD = 998244353;
int read() {
  char k = getchar();
  int x = 0;
  while (k < '0' || k > '9') k = getchar();
  while (k >= '0' && k <= '9') x = x * 10 + k - '0', k = getchar();
  return x;
}
struct SAM {
  SAM() { tot = las = 1; }
  struct node {
    int ch[2];
    int len, link;
  } a[MX * 2];
  int tot, las;
  int extend(int c) {
    int p = las, cur = las = ++tot;
    a[cur].len = a[p].len + 1;
    for (; p && !a[p].ch[c]; p = a[p].link) a[p].ch[c] = cur;
    if (!p) return a[cur].link = 1, cur;
    int q = a[p].ch[c];
    if (a[p].len + 1 == a[q].len) return a[cur].link = q, cur;
    int cl = ++tot;
    a[cl] = a[q];
    a[cl].len = a[p].len + 1;
    a[q].link = a[cur].link = cl;
    for (; p && a[p].ch[c] == q; p = a[p].link) a[p].ch[c] = cl;
    return cur;
  }
} A;
std::vector<int> vec[MX * 2];
int n;
char str[MX];
int main() {
  n = read();
  scanf("%s", str + 1);
  n = strlen(str + 1);
  long long ans = 0;
  int base = MX;
  for (int i = 1; i <= n; ++i) {
    if (i == 26) {
      ;
      ;
    }
    int type = str[i] == '(' ? 1 : -1;
    int add = A.extend(str[i] == '(');
    add = A.a[add].len - A.a[A.a[add].link].len;
    if (type == -1) {
      vec[base--].clear();
      auto kksk = std::upper_bound(vec[base].begin(), vec[base].end(), add);
      ;
      ;
      ans += kksk - vec[base].begin();
    } else {
      vec[base++].push_back(i);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
