#include <bits/stdc++.h>
using namespace std;
char s[500010];
int len;
struct State {
  int len, fa;
  int ch[30];
} pos[500010 << 1];
int tot = 1, las = 1;
int sum[500010];
long long ans;
set<pair<int, int> > P[500010 << 1 | 1];
set<pair<int, int> >::iterator it, it2;
int cnt[500010 << 1 | 1];
int ST[500010][20];
int logg[500010];
int cha(int l, int r) {
  if (!l) l = 1;
  int len = r - l + 1;
  int t = logg[len];
  return max(ST[l][t], ST[r - (1 << t) + 1][t]);
}
void insert(int t) {
  int p = las, np = las = ++tot;
  pos[np].len = pos[p].len + 1;
  for (; p && !pos[p].ch[t]; p = pos[p].fa) pos[p].ch[t] = np;
  if (!p)
    pos[np].fa = 1;
  else {
    int q = pos[p].ch[t];
    if (pos[q].len == pos[p].len + 1)
      pos[np].fa = q;
    else {
      int nq = ++tot;
      pos[nq] = pos[q];
      pos[nq].len = pos[p].len + 1;
      pos[np].fa = pos[q].fa = nq;
      for (; p && pos[p].ch[t] == q; p = pos[p].fa) pos[p].ch[t] = nq;
    }
  }
  int T = -1;
  int l = 0, r = pos[np].len;
  while (l <= r) {
    int mid = l + r >> 1;
    if (sum[pos[np].len] - cha(mid, pos[np].len) >= 0)
      T = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  if (T > pos[np].len - pos[pos[np].fa].len) return;
  it = P[sum[pos[np].len] + 500010].lower_bound(make_pair(T, -1));
  if (it == P[sum[pos[np].len] + 500010].end()) return;
  it2 = P[sum[pos[np].len] + 500010].lower_bound(
      make_pair(pos[np].len - pos[pos[np].fa].len, -1));
  if (it2 == P[sum[pos[np].len] + 500010].begin()) return;
  it2--;
  ans += (*it2).second - (*it).second + 1;
}
int main() {
  logg[0] = -1;
  for (int i = 1; i <= 500010 - 10; i++) logg[i] = logg[i >> 1] + 1;
  scanf("%d%s", &len, &s[1]);
  for (int i = 1; i <= len; i++) sum[i] = sum[i - 1] + (s[i] == '(' ? -1 : 1);
  for (int i = 1; i <= len; i++) ST[i][0] = sum[i];
  for (int j = 1; j <= 19; j++)
    for (int i = 1; i <= len; i++)
      if (i + (1 << j) - 1 <= len) {
        ST[i][j] = max(ST[i][j - 1], ST[i + (1 << (j - 1))][j - 1]);
      }
  int T = cha(6, 9);
  P[500010].insert(make_pair(0, ++cnt[500010]));
  for (int i = 1; i <= len; i++)
    P[sum[i] + 500010].insert(make_pair(i, ++cnt[sum[i] + 500010]));
  for (int i = 1; i <= len; i++) insert(s[i] == '(' ? 0 : 1);
  cout << ans;
  return 0;
}
