#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 333;
const long long linf = 1e18 + 333;
const int N = 5e5 + 5;
const int LOG = 19;
int n;
char s[N];
int a[N], go[N], suf[N], order[N], lcp_table[N], sum[N], size[N];
pair<pair<int, int>, int> p[N], temp_p[N];
void fast_sort() {
  for (int i = 1; i <= n; i++) size[p[i].first.second]++;
  sum[0] = 0;
  for (int i = 1; i < N; i++) {
    sum[i] = sum[i - 1] + size[i - 1];
    size[i - 1] = 0;
  }
  for (int i = 1; i <= n; i++) temp_p[++sum[p[i].first.second]] = p[i];
  for (int i = 1; i <= n; i++) size[temp_p[i].first.first]++;
  sum[0] = 0;
  for (int i = 1; i < N; i++) {
    sum[i] = sum[i - 1] + size[i - 1];
    size[i - 1] = 0;
  }
  for (int i = 1; i <= n; i++) p[++sum[temp_p[i].first.first]] = temp_p[i];
}
bool one_pass(int k) {
  for (int i = 1; i <= n; i++)
    p[i] = {{suf[i], i + (1 << k) <= n ? suf[i + (1 << k)] : 0}, i};
  fast_sort();
  int ptr = 1;
  for (int i = 1; i <= n; i++) {
    if (i - 1 >= 1 and p[i - 1].first != p[i].first) ptr++;
    suf[p[i].second] = ptr;
  }
  return ptr == n;
}
void build_sa() {
  for (int i = 1; i <= n; i++) suf[i] = s[i];
  for (int i = 0; i < LOG; i++)
    if (one_pass(i)) break;
  for (int i = 1; i <= n; i++) order[suf[i]] = i;
}
void build_lcp() {
  int j = 0;
  for (int i = 1; i <= n; i++) {
    if (suf[i] == 1) continue;
    while (i + j <= n and order[suf[i] - 1] + j <= n and
           s[i + j] == s[order[suf[i] - 1] + j])
      j++;
    lcp_table[suf[i]] = j;
    if (j) j--;
  }
}
vector<int> vs[N * 2];
int get(int x, int l, int r) {
  return upper_bound(vs[x + n].begin(), vs[x + n].end(), r) -
         lower_bound(vs[x + n].begin(), vs[x + n].end(), l);
}
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  build_sa();
  build_lcp();
  for (int i = 1; i <= n; i++) {
    a[i] = a[i - 1] + (s[i] == '(' ? +1 : -1);
    vs[a[i] + n].push_back(i);
  }
  vector<int> v;
  for (int i = n; i >= 1; i--) {
    while (v.size() and a[v.back() - 1] >= a[i - 1]) v.pop_back();
    go[i] = v.size() ? v.back() - 1 : n;
    v.push_back(i);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int x = order[i];
    int y = order[i] + lcp_table[i];
    if (y <= go[x]) {
      ans += get(a[x - 1], y, go[x]);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
