#include <bits/stdc++.h>
using namespace std;
struct SuffixArray {
  string a;
  int N, m;
  vector<int> SA, LCP, x, y, w, c;
  SuffixArray(string _a, int m = 256)
      : a(" " + _a),
        N(a.length()),
        m(m),
        SA(N),
        LCP(N),
        x(N),
        y(N),
        w(max(m, N)),
        c(N) {
    a[0] = 0;
    DA();
    kasaiLCP();
    {
      rotate(SA.begin(), SA.begin() + 1, SA.end());
      SA.pop_back();
    };
    {
      rotate(LCP.begin(), LCP.begin() + 1, LCP.end());
      LCP.pop_back();
    };
    a = a.substr(1, a.size());
    for (int i = 0; i < (int)SA.size(); ++i) --SA[i];
  }
  inline bool cmp(const int a, const int b, const int l) {
    return (y[a] == y[b] && y[a + l] == y[b + l]);
  }
  void Sort() {
    for (int i = 0; i < m; ++i) w[i] = 0;
    for (int i = 0; i < N; ++i) ++w[x[y[i]]];
    for (int i = 0; i < m - 1; ++i) w[i + 1] += w[i];
    for (int i = N - 1; i >= 0; --i) SA[--w[x[y[i]]]] = y[i];
  }
  void DA() {
    for (int i = 0; i < N; ++i) x[i] = a[i], y[i] = i;
    Sort();
    for (int i, j = 1, p = 1; p < N; j <<= 1, m = p) {
      for (p = 0, i = N - j; i < N; i++) y[p++] = i;
      for (int k = 0; k < N; ++k)
        if (SA[k] >= j) y[p++] = SA[k] - j;
      Sort();
      for (swap(x, y), p = 1, x[SA[0]] = 0, i = 1; i < N; ++i)
        x[SA[i]] = cmp(SA[i - 1], SA[i], j) ? p - 1 : p++;
    }
  }
  void kasaiLCP() {
    for (int i = 0; i < N; i++) c[SA[i]] = i;
    for (int i = 0, j, k = 0; i < N; LCP[c[i++]] = k)
      if (c[i] > 0)
        for (k ? k-- : 0, j = SA[c[i] - 1]; a[i + k] == a[j + k]; k++)
          ;
      else
        k = 0;
  }
};
const int N = 5e5 + 5;
struct wavelet_tree {
  int lo, hi;
  wavelet_tree *l, *r;
  vector<int> b;
  wavelet_tree(int *from, int *to, int x, int y) {
    lo = x, hi = y;
    if (lo == hi or from >= to) return;
    int mid = (lo + hi) / 2;
    auto f = [mid](int x) { return x <= mid; };
    b.reserve(to - from + 1);
    b.push_back(0);
    for (auto it = from; it != to; it++) b.push_back(b.back() + f(*it));
    auto pivot = stable_partition(from, to, f);
    l = new wavelet_tree(from, pivot, lo, mid);
    r = new wavelet_tree(pivot, to, mid + 1, hi);
  }
  int kth(int l, int r, int k) {
    if (l > r) return 0;
    if (lo == hi) return lo;
    int inLeft = b[r] - b[l - 1];
    int lb = b[l - 1];
    int rb = b[r];
    if (k <= inLeft) return this->l->kth(lb + 1, rb, k);
    return this->r->kth(l - lb, r - rb, k - inLeft);
  }
  int LTE(int l, int r, int k) {
    if (l > r or k < lo) return 0;
    if (hi <= k) return r - l + 1;
    int lb = b[l - 1], rb = b[r];
    return this->l->LTE(lb + 1, rb, k) + this->r->LTE(l - lb, r - rb, k);
  }
  int count(int l, int r, int k) {
    if (l > r or k < lo or k > hi) return 0;
    if (lo == hi) return r - l + 1;
    int lb = b[l - 1], rb = b[r], mid = (lo + hi) / 2;
    if (k <= mid) return this->l->count(lb + 1, rb, k);
    return this->r->count(l - lb, r - rb, k);
  }
};
int a[N], sp[N][22], lg[N], b[N];
int n;
void build() {
  for (int i = 0; 1 << i < N; i++) lg[1 << i] = i;
  for (int i = 1; i < N; i++) lg[i] = max(lg[i], lg[i - 1]);
  for (int i = 1; i <= n; i++) sp[i][0] = b[i];
  for (int i = 1; i < 22; i++) {
    for (int j = 1; j <= n; j++) {
      sp[j][i] = sp[j][i - 1];
      if (j + (1 << (i - 1)) <= n)
        sp[j][i] = min(sp[j][i], sp[j + (1 << (i - 1))][i - 1]);
      else
        break;
    }
  }
}
int get(int l, int r) {
  int k = lg[r - l + 1];
  return min(sp[l][k], sp[r - (1 << k) + 1][k]);
}
int bs(int l, int r) {
  int s = l, e = r, ans = -1;
  while (s <= e) {
    int mid = (s + e) >> 1;
    if (get(l, mid) >= b[l - 1])
      s = mid + 1, ans = mid;
    else
      e = mid - 1;
  }
  return ans;
}
int solve(wavelet_tree *tree, int l, int r) {
  int ind = bs(l, r);
  if (ind <= l) return 0;
  return tree->count(l, ind, b[l - 1]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> n >> s;
  int cnt = 0;
  a[0] = b[0] = N;
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == '(')
      cnt++;
    else
      cnt--;
    a[i] = cnt + N;
    b[i] = cnt + N;
  }
  build();
  wavelet_tree *tree = new wavelet_tree(a + 1, a + n + 1, 0, 2 * N + 10);
  SuffixArray suf(s);
  long long ans = 0;
  for (int i = 0; i < suf.LCP.size(); i++) {
    ans += solve(tree, suf.SA[i] + 1, n) -
           solve(tree, suf.SA[i] + 1, suf.SA[i] + suf.LCP[i]);
  }
  cout << ans << endl;
  return 0;
}
