#include <bits/stdc++.h>
using namespace std;
template <class _T>
inline void ina(_T a[], int n) {
  for (int i = 0; i < n; i++) cin >> (a[i]);
}
int TEST_CASE = 0;
template <class _T>
inline _T pow(_T a, _T b, _T m) {
  a %= m;
  _T ans = 1 % m;
  while (b) {
    if (b & 1) ans *= a, ans %= m;
    a *= a;
    a %= m;
    b >>= 1;
  }
  return ans;
}
template <class _T>
inline _T pow(_T a, _T b) {
  _T ans = 1;
  while (b) {
    if (b & 1) ans *= a;
    a *= a;
    b >>= 1;
  }
  return ans;
}
template <class _T>
inline _T add(_T a, _T b, _T m) {
  return a >= m - b ? a - (m - b) : a + b;
}
template <class _T>
inline _T multiply(_T a, _T b, _T m) {
  _T ans = 0;
  if (b > a) swap(a, b);
  while (b) {
    if (b & 1) ans = add(ans, a, m);
    b >>= 1;
    a = add(a, a, m);
  }
  return ans;
}
template <class _T>
inline _T bigpow(_T a, _T b, _T m) {
  a %= m;
  _T ans = 1 % m;
  while (b) {
    if (b & 1) ans = multiply(ans, a, m);
    a = multiply(a, a, m);
    b >>= 1;
  }
  return ans;
}
template <class _T>
inline _T modinvers(_T a, _T m) {
  return m > 2000000000LL ? bigpow(a, m - 2, m) : pow(a, m - 2, m);
}
template <class _T>
_T _egcd(_T a, _T b, _T &x, _T &y) {
  if (!b) {
    x = 1, y = 0;
    return a;
  }
  _T _g = _egcd(b, a % b, x, y);
  _T xt = x;
  x = y, y = xt - (a / b) * y;
  return _g;
}
template <class _T>
inline _T fmodinvers(_T a, _T m) {
  _T x, y;
  _egcd(a, m, x, y);
  x %= m;
  if (x < 0) x += m;
  return x;
}
template <class _T>
inline _T _lcm(_T a, _T b) {
  return (a * b) / __gcd(a, b);
}
template <class T>
inline T SQ(T a) {
  return a * a;
}
long long SQRT(long long n) {
  long long e = sqrt(n * 1.0);
  long long l = max(0LL, e - 2), r = min(n, e + 2);
  long long ans = 0;
  while (l <= r) {
    long long m = ((l + r) >> 1);
    if (m * m <= n)
      ans = m, l = m + 1;
    else
      r = m - 1;
  }
  return ans;
}
long long CBRT(long long n) {
  long long e = cbrt(n * 1.0);
  long long l = max(0LL, e - 2), r = min(n, e + 2);
  long long ans = 0;
  while (l <= r) {
    long long m = ((l + r) >> 1);
    if (m * m * m <= n)
      ans = m, l = m + 1;
    else
      r = m - 1;
  }
  return ans;
}
const long double EPS = 1e-9;
const long double PI = acos(-1.0);
long long mod = 1e9 + 7;
int cmp(int *r, int a, int b, int l) {
  return r[a] == r[b] && r[a + l] == r[b + l];
}
const int MX = 5e5 + 500;
int __a[MX], __b[MX], __c[MX], __d[MX];
int *calsa(int *a, int n, int m) {
  int *sa = __b, *b = __a, *x = __c, *y = __d, *t, i, j, p;
  memset(b, 0, m * sizeof(b[0]));
  for (i = 0; i < n; i++) b[x[i] = a[i]]++;
  for (i = 1; i < m; i++) b[i] += b[i - 1];
  for (i = n - 1; i >= 0; i--) sa[--b[x[i]]] = i;
  for (j = 1, p = 1; p < n; j <<= 1, m = p) {
    for (i = n - j, p = 0; i < n; i++) y[p++] = i;
    for (i = 0; i < n; i++)
      if (sa[i] >= j) y[p++] = sa[i] - j;
    memset(b, 0, m * sizeof(b[0]));
    for (i = 0; i < n; i++) b[x[y[i]]]++;
    for (i = 1; i < m; i++) b[i] += b[i - 1];
    for (i = n - 1; i >= 0; i--) sa[--b[x[y[i]]]] = y[i];
    for (t = x, x = y, y = t, x[sa[0]] = 0, i = 1, p = 1; i < n; i++)
      x[sa[i]] = cmp(y, sa[i], sa[i - 1], j) ? p - 1 : p++;
  }
  return sa;
}
int *calh(int *sa, int *a, int n) {
  int *r = __a, *h = __c, j, i, k;
  for (int i = 1; i < n; i++) r[sa[i]] = i;
  n--;
  for (int i = 0, k = 0; i < n; h[r[i++]] = (k ? k-- : k))
    for (j = sa[r[i] - 1]; a[i + k] == a[j + k]; k++)
      ;
  h[0] = 0;
  return h;
}
int t[20][MX];
vector<int> v[MX << 1];
void make_t(char *s, int n) {
  for (int i = 0; i < n; i++) {
    t[0][i] = t[0][i - 1] + (s[i] == '(' ? 1 : -1);
    v[t[0][i] + MX].push_back(i);
  }
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 0; i + (1 << j) <= n; i++) {
      t[j][i] = min(t[j - 1][i], t[j - 1][i + (1 << (j - 1))]);
    }
  }
}
inline int Min(int i, int j) {
  int k = floor(log2(j - i + 1));
  return min(t[k][i], t[k][j - (1 << k) + 1]);
}
int qry(int i, int j) {
  if (j <= i) return 0;
  int X = i ? t[0][i - 1] : 0;
  int L = i, R = j, ans = i - 1;
  while (L <= R) {
    int M = (L + R) >> 1;
    if (Min(i, M) >= X)
      ans = M, L = M + 1;
    else
      R = M - 1;
  }
  if (ans <= i) return 0;
  return upper_bound((v[X + MX]).begin(), (v[X + MX]).end(), ans) -
         lower_bound((v[X + MX]).begin(), (v[X + MX]).end(), i);
}
char s[MX];
int a[MX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n >> s;
  for (int i = 0; i < n; i++) a[i] = s[i] - '(' + 1;
  int *sa = calsa(a, n + 1, 3);
  int *lcp = calh(sa, a, n + 1);
  make_t(s, n);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += qry(sa[i], n - 1) - qry(sa[i], sa[i] + lcp[i] - 1);
  }
  cout << ans << '\n';
  return 0;
}
