#include <bits/stdc++.h>
static char buff[(int)1e6 + 17];
static constexpr long long inf = (long long)1e9 + 7ll;
inline void config_io(const bool& __fastio) {
  if (__fastio) {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
  }
  if (!std::string("").empty()) {
    assert(
        freopen(""
                ".in",
                "r", stdin));
    assert(
        freopen(""
                ".out",
                "w", stdout));
  }
}
using namespace std;
const int maxn = (int)1e6 + 17;
int n, maxsymb = 3;
string text_s;
int text[maxn], suff[maxn], c[maxn];
pair<pair<int, int>, int> p[maxn];
int lcp[maxn], pos[maxn];
int st[19][maxn], lg[maxn];
vector<int> ids[2 * maxn];
int bal[maxn];
void build() {
  for (int i = 0; i < n; ++i) c[i] = text[i];
  for (int h = 0; h < 19; ++h) {
    for (int i = 0; i < n; ++i) p[i] = {{c[i], c[i + (1 << h)]}, i};
    sort(p, p + n);
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
      c[p[i].second] = cnt;
      cnt += p[i].first != p[i + 1].first;
    }
    if (cnt == n) break;
  }
  for (int i = 0; i < n; ++i) suff[c[i]] = i;
}
void kasai() {
  for (int i = 0; i < n; ++i) pos[suff[i]] = i;
  int k = 0;
  for (int i = 0; i < n; ++i) {
    k = max(0, k - 1);
    if (pos[i] == n - 1)
      lcp[pos[i]] = -1;
    else {
      int j = suff[pos[i] + 1];
      for (; max(i, j) + k < n && text[i + k] == text[j + k]; ++k)
        ;
      lcp[pos[i]] = k;
    }
  }
}
void build_st() {
  for (int i = 1, l = 0; i <= n; ++i) {
    l += ((1 << (l + 1)) == i);
    lg[i] = l;
  }
  for (int i = 0; i < n - 1; ++i) st[0][i] = bal[i];
  for (int k = 1; k <= lg[n - 1]; ++k)
    for (int i = 0; i + (1 << (k - 1)) < n - 1; ++i)
      st[k][i] = min(st[k - 1][i], st[k - 1][i + (1 << (k - 1))]);
}
int getmin(int l, int r) {
  int k = lg[r - l + 1];
  return min(st[k][l], st[k][r - (1 << k) + 1]);
}
int getlower(int l, int r, int b) {
  if (l > r) return 0;
  int lf = lower_bound(ids[b].begin(), ids[b].end(), l) - ids[b].begin();
  int rg = lower_bound(ids[b].begin(), ids[b].end(), r) - ids[b].begin();
  if (rg < ((int)ids[b].size()) && ids[b][rg] == r) ++rg;
  return rg - lf;
}
int main() {
  config_io(false);
  scanf("%d", &n);
  n = 0;
  int id = 0;
  while (scanf("%s", buff) == 1) {
    string t = string(buff);
    for (int i = 0, b = maxn; i < ((int)t.size()); ++i) {
      text[n++] = 1 + t[i] - '(';
      b += (t[i] == '(') - (t[i] == ')');
      ids[b].push_back(i);
      bal[i] = b;
    }
    text_s += t + "#";
    text[n++] = id++;
  }
  build();
  kasai();
  build_st();
  long long ans = 0ll;
  for (int i = 1; i < n; ++i)
    if (text_s[suff[i]] == '(') {
      int j = suff[i], l = lcp[i - 1], lf, rg;
      for (lf = j, rg = n - 2; lf < rg;) {
        int m = (lf + rg + 1) / 2;
        if (getmin(j, m) >= bal[j] - 1)
          lf = m;
        else
          rg = m - 1;
      }
      ans += getlower(j + l, rg, bal[j] - 1);
    } else
      break;
  printf("%I64d\n", ans);
  return 0;
}
