#include <bits/stdc++.h>
const int N = 5e5 + 5;
const int logN = 20;
struct SufAuto {
  static const int V = N << 1;
  static const int S = 2;
  int ch[V][S], link[V], len[V], epos[V];
  int last, total;
  inline SufAuto() {
    last = total = 1;
    memset(ch, 0, sizeof(ch));
    memset(link, 0, sizeof(link));
    memset(len, 0, sizeof(len));
    memset(epos, 0, sizeof(epos));
  }
  inline void extend(int c, int i) {
    int p = last, np = last = ++total;
    len[np] = len[p] + 1, epos[np] = i;
    for (; p && !ch[p][c]; p = link[p]) ch[p][c] = np;
    if (!p) {
      link[np] = 1;
      return;
    }
    int q = ch[p][c];
    if (len[q] == len[p] + 1) {
      link[np] = q;
      return;
    }
    int nq = ++total;
    memcpy(ch[nq], ch[q], S << 2), len[nq] = len[p] + 1;
    link[nq] = link[q], epos[nq] = epos[q], link[q] = link[np] = nq;
    for (; p && ch[p][c] == q; p = link[p]) ch[p][c] = nq;
  }
  long long solve();
} SAM;
char s[N];
int n, suf[N];
int st[logN][N], lg2[N];
inline void init_st() {
  memset(st, 0x3f, sizeof(st));
  memcpy(st[0], suf, sizeof(suf));
  for (int j = 1; j < logN; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      st[j][i] = std::min(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);
  lg2[0] = -1;
  for (int i = 1; i <= n; i++) lg2[i] = lg2[i >> 1] + 1;
}
inline int get_min(int l, int r) {
  int t = lg2[r - l + 1];
  return std::min(st[t][l], st[t][r - (1 << t) + 1]);
}
std::vector<int> occur[N << 1];
inline void init_occur() {
  for (int i = 1; i <= n; i++) occur[suf[i] + N].push_back(i);
}
inline int get_occur(int l, int r, int v) {
  return std::upper_bound(occur[v + N].begin(), occur[v + N].end(), r) -
         std::lower_bound(occur[v + N].begin(), occur[v + N].end(), l);
}
long long SufAuto::solve() {
  long long ans = 0;
  for (int x = 2; x <= total; x++) {
    if (s[epos[x]] == '(') continue;
    int tl = epos[x] - len[x] + 1;
    int tr = epos[x] - len[link[x]], forward = -1;
    while (tl <= tr) {
      int mid = (tl + tr) >> 1;
      if (get_min(mid, epos[x]) >= suf[epos[x] + 1])
        forward = mid, tr = mid - 1;
      else
        tl = mid + 1;
    }
    if (forward == -1) continue;
    int tmp = get_occur(forward, epos[x] - len[link[x]], suf[epos[x] + 1]);
    ans += tmp;
  }
  return ans;
}
signed main() {
  scanf("%d%s", &n, s + 1);
  for (int i = 1; i <= n; i++) SAM.extend(s[i] - '(', i);
  for (int i = n; i >= 1; i--) suf[i] = suf[i + 1] + (s[i] == '(' ? -1 : 1);
  init_st(), init_occur();
  printf("%lld\n", SAM.solve());
  return 0;
}
