#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
vector<int> pos[1000100];
int sum[500050];
char s[500050];
inline int idx(char c) { return c == '(' ? 0 : 1; }
struct SAM {
  int ch[500050 * 2][2], fa[500050 * 2], l[500050 * 2], cnt[500050],
      topo[500050 * 2];
  long long cc[500050 * 2];
  int rr[500050 * 2];
  int last, sz;
  void init() {
    last = sz = 1;
    fa[1] = l[1] = 0;
    memset(ch[1], 0, sizeof(ch[1]));
  }
  inline int newnode() {
    sz++;
    memset(ch[sz], 0, sizeof(ch[sz]));
    fa[sz] = l[sz] = 0;
    return sz;
  }
  void add(int c, int idx) {
    int p = last;
    int np = newnode();
    l[np] = l[p] + 1;
    last = np;
    cc[np]++, rr[np] = idx;
    while (p && !ch[p][c]) ch[p][c] = np, p = fa[p];
    if (!p)
      fa[np] = 1;
    else {
      int q = ch[p][c];
      if (l[q] == l[p] + 1)
        fa[np] = q;
      else {
        int nq = ++sz;
        l[nq] = l[p] + 1;
        memcpy(ch[nq], ch[q], sizeof(ch[q]));
        fa[nq] = fa[q];
        fa[np] = fa[q] = nq;
        while (ch[p][c] == q) ch[p][c] = nq, p = fa[p];
      }
    }
  }
  void rs(int alen) {
    memset(cnt, 0, sizeof(cnt));
    for (int i = (1); i <= (int)(sz); i++) cnt[l[i]]++;
    for (int i = (1); i <= (int)(alen); i++) cnt[i] += cnt[i - 1];
    for (int i = sz; i; i--) topo[cnt[l[i]]--] = i;
  }
  void sol() {
    long long ans = 0;
    for (int i = sz; i >= 2; i--) {
      int u = topo[i];
      rr[fa[u]] = rr[u];
    }
    for (int i = 2; i <= sz; i++) {
      int sl = rr[i] - l[i] + 1, nr = rr[i] - l[fa[i]];
      int key = sum[rr[i] + 1] + 500005;
      int nl = -1;
      int p = upper_bound(pos[key - 1].begin(), pos[key - 1].end(), rr[i]) -
              pos[key - 1].begin();
      if (p - 1 == -1)
        nl = sl;
      else {
        int t = pos[key - 1][p - 1];
        if (t < sl)
          nl = sl;
        else
          nl = t + 1;
      }
      if (nl > nr) {
        continue;
      }
      long long res = upper_bound(pos[key].begin(), pos[key].end(), nr) -
                      lower_bound(pos[key].begin(), pos[key].end(), nl);
      ans = ans + res;
    }
    printf("%lld\n", ans);
  }
};
SAM sam;
int n;
void init() {}
int main() {
  cin >> n;
  scanf("%s", s);
  sam.init();
  for (int i = (0); i < (int)(n); i++) sam.add(idx(s[i]), i);
  sam.rs(n + 2);
  for (int i = n - 1; i >= 0; i--) {
    sum[i] = sum[i + 1] + (s[i] == ')' ? 1 : -1);
  }
  for (int i = (0); i < (int)(n); i++) pos[sum[i] + 500005].push_back(i);
  sam.sol();
  return 0;
}
