#include <bits/stdc++.h>
using namespace std;
const int N = 505050;
namespace SA {
const static int N = ::N;
int sa[N], rk[N], ht[N], s[N << 1], t[N << 1], p[N], cnt[N], cur[N];
void sais(int n, int m, int *s, int *t, int *p) {
  int n1 = t[n - 1] = 0, ch = rk[0] = -1, *s1 = s + n;
  for (int i = n - 2; ~i; i--)
    t[i] = s[i] == s[i + 1] ? t[i + 1] : s[i] > s[i + 1];
  for (int i = 1; i < n; i++)
    rk[i] = t[i - 1] && !t[i] ? (p[n1] = i, n1++) : -1;
  std::fill_n(sa, n, -1);
  std::fill_n(cnt, m, 0);
  for (int i = 0; i < n; i++) cnt[s[i]]++;
  for (int i = 1; i < m; i++) cnt[i] += cnt[i - 1];
  for (int i = 0; i < m; i++) cur[i] = cnt[i] - 1;
  for (int i = n1 - 1; ~i; i--) sa[cur[s[p[i]]]--] = p[i];
  for (int i = 1; i < m; i++) cur[i] = cnt[i - 1];
  for (int i = 0; i < n; i++)
    if (sa[i] > 0 && t[sa[i] - 1]) sa[cur[s[sa[i] - 1]]++] = sa[i] - 1;
  for (int i = 0; i < m; i++) cur[i] = cnt[i] - 1;
  for (int i = n - 1; ~i; i--)
    if (sa[i] > 0 && !t[sa[i] - 1]) sa[cur[s[sa[i] - 1]]--] = sa[i] - 1;
  for (int i = 0, x, y; i < n; i++)
    if (~(x = rk[sa[i]])) {
      if (ch < 1 || p[x + 1] - p[x] != p[y + 1] - p[y])
        ch++;
      else
        for (int j = p[x], k = p[y]; j <= p[x + 1]; j++, k++)
          if ((s[j] << 1 | t[j]) != (s[k] << 1 | t[k])) {
            ch++;
            break;
          }
      s1[y = x] = ch;
    }
  if (ch + 1 < n1)
    sais(n1, ch + 1, s1, t + n, p + n1);
  else
    for (int i = 0; i < n1; i++) sa[s1[i]] = i;
  for (int i = 0; i < n1; i++) s1[i] = p[sa[i]];
  std::fill_n(sa, n, -1);
  std::fill_n(cnt, m, 0);
  for (int i = 0; i < n; i++) cnt[s[i]]++;
  for (int i = 1; i < m; i++) cnt[i] += cnt[i - 1];
  for (int i = 0; i < m; i++) cur[i] = cnt[i] - 1;
  for (int i = n1 - 1; ~i; i--) sa[cur[s[s1[i]]]--] = s1[i];
  for (int i = 1; i < m; i++) cur[i] = cnt[i - 1];
  for (int i = 0; i < n; i++)
    if (sa[i] > 0 && t[sa[i] - 1]) sa[cur[s[sa[i] - 1]]++] = sa[i] - 1;
  for (int i = 0; i < m; i++) cur[i] = cnt[i] - 1;
  for (int i = n - 1; ~i; i--)
    if (sa[i] > 0 && !t[sa[i] - 1]) sa[cur[s[sa[i] - 1]]--] = sa[i] - 1;
}
template <typename T>
int mapCharToInt(int n, const T *str) {
  int m = *max_element(str, str + n);
  std::fill_n(rk, m + 1, 0);
  for (int i = 0; i < n; i++) rk[str[i]] = 1;
  for (int i = 0; i < m; i++) rk[i + 1] += rk[i];
  for (int i = 0; i < n; i++) s[i] = rk[str[i]] - 1;
  return rk[m];
}
template <typename T>
void suffixArray(int n, const T *str) {
  int m = mapCharToInt(++n, str);
  sais(n, m, s, t, p);
  for (int i = 0; i < n; i++) rk[sa[i]] = i;
  for (int i = 0, h = ht[0] = 0; i < n - 1; i++) {
    int j = sa[rk[i] - 1];
    while (i + h < n && j + h < n && s[i + h] == s[j + h]) h++;
    if (ht[rk[i]] = h) h--;
  }
}
};  // namespace SA
int n;
int a[N], pre[N];
string s;
struct Seg {
  static const int N = ::N << 2;
  int mi[N], cnt[N];
  void build(int l, int r, int rt) {
    if (l == r) {
      mi[rt] = pre[l];
      cnt[rt] = 1;
      return;
    }
    int mid = l + r >> 1;
    build(l, mid, rt << 1);
    build(mid + 1, r, rt << 1 | 1);
    mi[rt] = min(mi[rt << 1], mi[rt << 1 | 1]);
    cnt[rt] = 0;
    if (mi[rt] == mi[rt << 1]) cnt[rt] += cnt[rt << 1];
    if (mi[rt] == mi[rt << 1 | 1]) cnt[rt] += cnt[rt << 1 | 1];
  }
  int qry(int L, int R, int c, int l, int r, int rt) {
    if (L <= l && r <= R && (l == r || mi[rt] >= c)) {
      if (mi[rt] >= c) return n;
      return l;
    }
    int mid = l + r >> 1;
    if (L <= mid) {
      int t = qry(L, R, c, l, mid, rt << 1);
      if (t != n) return t;
    }
    if (R > mid) {
      int t = qry(L, R, c, mid + 1, r, rt << 1 | 1);
      if (t != n) return t;
    }
    return n;
  }
  int qry2(int L, int R, int c, int l, int r, int rt) {
    if (L > R) return 0;
    if (L <= l && r <= R) return (mi[rt] == c) ? cnt[rt] : 0;
    int mid = l + r >> 1, res = 0;
    if (L <= mid) res += qry2(L, R, c, l, mid, rt << 1);
    if (R > mid) res += qry2(L, R, c, mid + 1, r, rt << 1 | 1);
    return res;
  }
} seg;
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  cin >> n >> s;
  for (int i = (0); i < (n); ++i) a[i] = (s[i] == ')') + 1;
  SA::suffixArray(n, a);
  pre[0] = (s[0] == '(') ? 1 : -1;
  for (int i = (1); i < (n); ++i)
    pre[i] = pre[i - 1] + ((s[i] == '(') ? 1 : -1);
  long long ans = 0;
  seg.build(0, n - 1, 1);
  for (int i = (1); i < (n + 1); ++i) {
    int t = SA::sa[i], c = (t - 1 >= 0) ? pre[t - 1] : 0;
    int l = SA::sa[i] + SA::ht[i];
    int r = seg.qry(t, n - 1, c, 0, n - 1, 1);
    ans += seg.qry2(l, r - 1, c, 0, n - 1, 1);
  }
  cout << ans << "\n";
  return 0;
}
