#include <bits/stdc++.h>
using namespace std;
const int maxx = 500010;
char s[maxx];
int sum[maxx];
int mi[maxx][30];
vector<int> v[2 * maxx];
int y[maxx], x[maxx], c[maxx], sa[maxx];
int rk[maxx], height[maxx];
int n, m;
void get_sa() {
  for (int i = 1; i <= m; i++) c[i] = 0;
  for (int i = 1; i <= n; i++) c[x[i] = s[i]]++;
  for (int i = 2; i <= m; i++) c[i] += c[i - 1];
  for (int i = n; i >= 1; i--) sa[c[x[i]]--] = i;
  for (int k = 1; k <= n; k <<= 1) {
    int num = 0;
    for (int i = n - k + 1; i <= n; i++) y[++num] = i;
    for (int i = 1; i <= n; i++)
      if (sa[i] > k) y[++num] = sa[i] - k;
    for (int i = 1; i <= m; i++) c[i] = 0;
    for (int i = 1; i <= n; i++) c[x[i]]++;
    for (int i = 2; i <= m; i++) c[i] += c[i - 1];
    for (int i = n; i >= 1; i--) sa[c[x[y[i]]]--] = y[i], y[i] = 0;
    swap(x, y);
    x[sa[1]] = 1;
    num = 1;
    for (int i = 2; i <= n; i++)
      x[sa[i]] = (y[sa[i]] == y[sa[i - 1]] && y[sa[i] + k] == y[sa[i - 1] + k])
                     ? num
                     : ++num;
    if (num == n) break;
    m = num;
  }
}
void get_height() {
  int k = 0;
  for (int i = 1; i <= n; i++) rk[sa[i]] = i;
  for (int i = 1; i <= n; i++) {
    if (rk[i] == 1) continue;
    if (k) k--;
    int j = sa[rk[i] - 1];
    while (j + k <= n && i + k <= n && s[i + k] == s[j + k]) k++;
    height[rk[i]] = k;
  }
}
int getmi(int l, int r) {
  int k = log2(r - l + 1);
  return mi[l][k] < mi[r - (1 << k) + 1][k] ? mi[l][k]
                                            : mi[r - (1 << k) + 1][k];
}
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + (s[i] == '(' ? 1 : -1);
  sum[0] = maxx;
  for (int i = 1; i <= n; i++) sum[i] += maxx;
  for (int i = 1; i <= n; i++) mi[i][0] = sum[i];
  for (int j = 1; 1 << j <= n; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      mi[i][j] = min(mi[i][j - 1], mi[i + (1 << (j - 1))][j - 1]);
  for (int i = 1; i <= n; i++) v[sum[i]].push_back(i);
  m = 50;
  get_sa();
  get_height();
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (s[sa[i]] == ')') continue;
    int l = sa[i] + height[i], r = n, res = l - 1;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (getmi(sa[i], mid) >= sum[sa[i] - 1])
        l = mid + 1, res = mid;
      else
        r = mid - 1;
    }
    int t = sum[sa[i] - 1];
    ans += upper_bound(v[t].begin(), v[t].end(), res) -
           lower_bound(v[t].begin(), v[t].end(), sa[i] + height[i]);
  }
  printf("%lld\n", ans);
  return 0;
}
