#include <bits/stdc++.h>
using namespace std;
int n, cnt, num, lt, mn, mx, _last[1000010UL], w[1000010UL], fa[1000010UL],
    ch[1000010UL][2], Rt, sn[1000010UL], R[1000010UL], L[1000010UL],
    ti[1000010UL];
char s[1000010UL];
long long ans;
struct ME {
  int pos, zhi, v;
  friend bool operator<(ME x, ME y) { return x.pos < y.pos; }
} sg[1000010UL << 1];
void Extend(int x, int pos) {
  int np = ++num, p = lt;
  sn[np] = sn[p] + 1;
  while (p && (!ch[p][x])) ch[p][x] = np, p = fa[p];
  if (!p)
    fa[np] = Rt;
  else {
    int q = ch[p][x];
    if (sn[q] == sn[p] + 1)
      fa[np] = q;
    else {
      int nq = ++num;
      R[nq] = pos;
      sn[nq] = sn[p] + 1;
      memcpy(ch[nq], ch[q], sizeof(ch[nq]));
      fa[nq] = fa[q], fa[q] = fa[np] = nq;
      while (p && ch[p][x] == q) ch[p][x] = nq, p = fa[p];
    }
  }
  R[np] = pos;
  lt = np;
  return;
}
int main() {
  num = lt = Rt = 1;
  scanf("%d", &n);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; ++i) Extend(s[i] == ')', i);
  for (int i = n; i >= 1; --i) {
    w[i] = w[i + 1] + (s[i] == ')' ? -1 : 1);
    if (w[i] < mn) mn = w[i];
  }
  for (int i = n; i >= 1; --i) {
    w[i] -= (mn - 1);
    if (w[i] > mx) mx = w[i];
  }
  for (int i = 1; i <= n; ++i) {
    _last[w[i]] = i;
    int nw = w[i] + (s[i] == ')' ? 1 : -1);
    if (_last[nw + 1])
      L[i] = _last[nw + 1] + 1;
    else
      L[i] = 1;
  }
  for (int i = 2; i <= num; ++i) {
    int l = R[i] - sn[i] + 1, r = R[i] - sn[fa[i]];
    l = max(l, L[R[i]]);
    if (l > r) continue;
    int nw = w[R[i]] + (s[R[i]] == ')' ? 1 : -1);
    ++cnt, sg[cnt].pos = r, sg[cnt].zhi = nw, sg[cnt].v = 1;
    if (l > 1) ++cnt, sg[cnt].pos = l - 1, sg[cnt].zhi = nw, sg[cnt].v = -1;
  }
  sort(sg + 1, sg + cnt + 1);
  for (int i = 1, j = 1; i <= n && j <= cnt; ++i) {
    ++ti[w[i]];
    while (j <= cnt && sg[j].pos == i) {
      ans += 1ll * sg[j].v * ti[sg[j].zhi];
      ++j;
    }
  }
  printf("%I64d", ans);
  return 0;
}
