#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500100;
const int MAXLG = 20;
long long key[MAXN];
int n;
int lcp[MAXN], p[MAXN], c[MAXN];
struct Cmp {
  bool operator()(int i, int j) const { return key[i] < key[j]; }
};
void build_sa(string &text) {
  n = text.size();
  for (int i = 0; i < n; i++) {
    p[i] = i;
    key[i] = text[i];
  }
  sort(p, p + n, Cmp());
  for (int k = 1;; k *= 2) {
    for (int i = 0; i < n; i++) {
      c[p[i]] = (i > 0 && key[p[i]] == key[p[i - 1]]) ? c[p[i - 1]] : i;
    }
    if (k >= n) {
      break;
    }
    for (int i = 0; i < n; i++) {
      key[i] = (long long)c[i] * (long long)(n + 1ll) +
               (long long)(i + k < n ? c[i + k] + 1 : 0);
    }
    sort(p, p + n, Cmp());
  }
  for (int i = 0, k = 0; i < n; i++) {
    if (k > 0) {
      k--;
    }
    if (c[i] == n - 1) {
      lcp[c[i]] = 0;
      continue;
    }
    int j = p[c[i] + 1];
    while (max(i, j) + k < n && text[i + k] == text[j + k]) {
      k++;
    }
    lcp[c[i]] = k;
  }
}
int L[MAXN], R[MAXN];
int v[MAXN];
int mn[MAXN][MAXLG];
int lg[MAXN];
void build_st() {
  mn[0][0] = v[0];
  for (int i = 1; i <= n; i++) {
    lg[i] = lg[i - 1];
    if ((1 << (lg[i] + 1)) == i) {
      lg[i]++;
    }
    mn[i][0] = v[i];
  }
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 0; i + (1 << (j - 1)) < n; i++) {
      mn[i][j] = min(mn[i][j - 1], mn[i + (1 << (j - 1))][j - 1]);
    }
  }
}
int query_st(int i, int j) {
  if (i > j) {
    swap(i, j);
  }
  int log = lg[j - i + 1];
  return min(mn[i][log], mn[j - (1 << log) + 1][log]);
}
pair<int, pair<int, int> > qs[MAXN];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  string s;
  cin >> s;
  build_sa(s);
  L[p[0]] = 1;
  for (int i = 1; i < n; i++) {
    L[p[i]] = lcp[i - 1] + 1;
  }
  for (int i = 0; i < n; i++) {
    v[i] = 0;
    if (s[i] == '(') {
      v[i]++;
    } else {
      v[i]--;
    }
    if (i > 0) {
      v[i] += v[i - 1];
    }
  }
  build_st();
  for (int i = 0; i < n; i++) {
    int vi = 0;
    if (i > 0) {
      vi = v[i - 1];
    }
    R[i] = 0;
    int l = L[i], r = n - i;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (query_st(i, i + mid - 1) >= vi) {
        R[i] = mid;
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
  }
  int sz = 0;
  for (int i = 0; i < n; i++) {
    if (L[i] > 0 && L[i] <= R[i]) {
      int val = 0;
      if ((i + L[i] - 2) >= 0) {
        val = v[i - 1];
        qs[sz++] =
            pair<int, pair<int, int> >((i + L[i] - 2), pair<int, int>(-1, val));
      }
      qs[sz++] =
          pair<int, pair<int, int> >((i + R[i] - 1), pair<int, int>(1, val));
    }
  }
  sort(qs, qs + sz);
  long long sol = 0ll;
  map<int, int> dic;
  int iq = 0;
  for (int i = 0; i < n; i++) {
    dic[v[i]]++;
    while (iq < sz && qs[iq].first <= i) {
      sol += qs[iq].second.first * dic[qs[iq].second.second];
      iq++;
    }
  }
  cout << sol << '\n';
}
