#include <bits/stdc++.h>
using namespace std;
vector<int> suffix_array(string s) {
  int n = s.size(), eqcl = 1;
  vector<int> p(n), c(n), pn(n), cn(n), f(200, 0);
  for (char i : s) f[i]++;
  for (int i = 1; i < f.size(); i++) f[i] += f[i - 1];
  for (int i = 0; i < n; i++) p[--f[s[i]]] = i;
  c[p[0]] = 0;
  for (int i = 1; i < n; i++) {
    if (s[p[i]] != s[p[i - 1]]) eqcl++;
    c[p[i]] = eqcl - 1;
  }
  for (int h = 0; (1 << h) < n; h++) {
    f.assign(eqcl, 0);
    for (int i = 0; i < n; i++) pn[i] = (p[i] - (1 << h) + n) % n;
    for (int i = 0; i < n; i++) f[c[p[i]]]++;
    for (int i = 1; i < eqcl; i++) f[i] += f[i - 1];
    for (int i = n - 1; i >= 0; i--) p[--f[c[pn[i]]]] = pn[i];
    eqcl = 1;
    cn[p[0]] = 0;
    for (int i = 1; i < n; i++) {
      pair<int, int> now(c[p[i]], c[(p[i] + (1 << h)) % n]),
          pv(c[p[i - 1]], c[(p[i - 1] + (1 << h)) % n]);
      if (now != pv) eqcl++;
      cn[p[i]] = eqcl - 1;
    }
    c = cn;
  }
  return p;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  s.push_back('#');
  const int offset = n;
  vector<vector<int> > f(2 * n + 79);
  vector<int> pf(n + 1, offset);
  for (int i = 0; i < n; i++) pf[i + 1] = pf[i] + ((s[i] == '(') ? 1 : -1);
  for (int i = 0; i <= n; i++) f[pf[i]].push_back(i);
  vector<int> sf = suffix_array(s), ip(s.size()), lcp(s.size());
  for (int i = 0; i < s.size(); i++) ip[sf[i]] = i;
  for (int i = 0, k = 0; i < s.size(); i++, k = (k ? k - 1 : 0)) {
    if (ip[i] == s.size() - 1) {
      k = 0;
      continue;
    }
    int j = sf[ip[i] + 1];
    while (i + k < s.size() && j + k < s.size() && s[i + k] == s[j + k]) k++;
    lcp[j] = k;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int l = i + lcp[i] + 1, r = n;
    auto it = lower_bound(f[pf[i] - 1].begin(), f[pf[i] - 1].end(), i);
    if (it != f[pf[i] - 1].end()) r = *it;
    if (l <= r)
      ans += upper_bound(f[pf[i]].begin(), f[pf[i]].end(), r) -
             lower_bound(f[pf[i]].begin(), f[pf[i]].end(), l);
  }
  cout << ans << "\n";
  return 0;
}
