#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
int x, y, i, j, n, r;
int P[20][N], Q[N], mn[4 * N], cnt[4 * N], lazy[4 * N];
long long ans = 0;
vector<pair<pair<int, int>, int> > W;
char temp[N];
pair<pair<int, int>, int> t[N];
string str;
int lcp(int x, int y) {
  x = Q[x];
  y = Q[y];
  int ans = 0;
  for (int i = 19; i >= 0; i--)
    if (P[i][x] == P[i][y]) {
      ans += 1 << i;
      x += 1 << i;
      y += 1 << i;
    }
  return ans;
}
void init(int root, int bas, int son) {
  if (bas == son) {
    cnt[root] = 1;
    return;
  }
  init((root + root), bas, ((bas + son) / 2));
  init((root + root + 1), ((bas + son) / 2) + 1, son);
  cnt[root] = cnt[(root + root)] + cnt[(root + root + 1)];
}
void push(int root, int bas, int son) {
  mn[(root + root)] += lazy[root];
  mn[(root + root + 1)] += lazy[root];
  lazy[(root + root)] += lazy[root];
  lazy[(root + root + 1)] += lazy[root];
  lazy[root] = 0;
}
void update(int root, int bas, int son, int x, int y, int v) {
  if (bas > y or son < x) return;
  if (x <= bas and son <= y) {
    mn[root] += v;
    lazy[root] += v;
    return;
  }
  push(root, bas, son);
  update((root + root), bas, ((bas + son) / 2), x, y, v);
  update((root + root + 1), ((bas + son) / 2) + 1, son, x, y, v);
  if (mn[(root + root)] == mn[(root + root + 1)]) {
    mn[root] = mn[(root + root)];
    cnt[root] = cnt[(root + root)] + cnt[(root + root + 1)];
  } else if (mn[(root + root)] < mn[(root + root + 1)]) {
    mn[root] = mn[(root + root)];
    cnt[root] = cnt[(root + root)];
  } else {
    mn[root] = mn[(root + root + 1)];
    cnt[root] = cnt[(root + root + 1)];
  }
}
int query2(int root, int bas, int son, int x, int y) {
  if (bas > y or son < x) return n;
  if (mn[root] >= 0) return n;
  if (bas == son) return bas;
  push(root, bas, son);
  int q = query2((root + root), bas, ((bas + son) / 2), x, y);
  if (q != n) return q;
  return query2((root + root + 1), ((bas + son) / 2) + 1, son, x, y);
}
pair<int, int> query(int root, int bas, int son, int x, int y) {
  if (bas > y or son < x) return make_pair(inf, 0);
  if (x <= bas and son <= y) return make_pair(mn[root], cnt[root]);
  push(root, bas, son);
  pair<int, int> t1 = query((root + root), bas, ((bas + son) / 2), x, y);
  pair<int, int> t2 =
      query((root + root + 1), ((bas + son) / 2) + 1, son, x, y);
  if (t1.first == t2.first) return make_pair(t1.first, t1.second + t2.second);
  if (t1.first < t2.first) return t1;
  return t2;
}
int main() {
  cin >> n;
  scanf("%s", temp);
  str = temp;
  x = 0;
  y = str.size();
  for (i = 0; i < str.size(); i++) P[0][i] = str[i];
  for (i = 1; i <= 19; i++) {
    for (j = 0; j < str.size(); j++) {
      if (j + (1 << i - 1) < str.size())
        t[j] = make_pair(make_pair(P[i - 1][j], P[i - 1][j + (1 << i - 1)]), j);
      else
        t[j] = make_pair(make_pair(P[i - 1][j], -1), j);
    }
    sort(t, t + str.size());
    int s = 0;
    for (j = 0; j < str.size(); j++) {
      if (j != 0 and t[j].first == t[j - 1].first)
        P[i][t[j].second] = P[i][t[j - 1].second];
      else
        P[i][t[j].second] = ++s;
      if (i == 19) Q[j] = t[j].second;
    }
  }
  int n = str.size();
  W.push_back(make_pair(make_pair(Q[0], n - 1), 1));
  for (i = 1; i < n; i++) {
    int t = lcp(i - 1, i);
    W.push_back(make_pair(make_pair(Q[i], n - 1), 1));
    if (t) W.push_back(make_pair(make_pair(Q[i], Q[i] + t - 1), -1));
  }
  sort(W.begin(), W.end(), greater<pair<pair<int, int>, int> >());
  r = n - 1;
  init(1, 0, n - 1);
  for (i = 0; i < W.size(); i++) {
    while (r >= W[i].first.first) {
      update(1, 0, n - 1, r, n - 1, str[r] == '(' ? 1 : -1);
      r--;
    }
    int q = query2(1, 0, n - 1, W[i].first.first, W[i].first.second) - 1;
    if (min(q, W[i].first.second) >= W[i].first.first) {
      pair<int, int> t1 =
          query(1, 0, n - 1, W[i].first.first, min(q, W[i].first.second));
      ans += W[i].second * (t1.first == 0 ? t1.second : 0);
    }
  }
  printf("%lld\n", ans);
}
