#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
const int L = 20;
const int inf = 1e9 + 10;
int ps[N], Rank[N][L], P[N], nxt[N], n, pw;
pair<pair<int, int>, int> tmp[N];
vector<int> vec[2 * N];
stack<int> st;
bool cmp(int x, int y) {
  if (Rank[x][pw - 1] != Rank[y][pw - 1])
    return Rank[x][pw - 1] < Rank[y][pw - 1];
  if (n < max(x, y) + (1 << (pw - 1))) return y < x;
  return Rank[x + (1 << (pw - 1))][pw - 1] < Rank[y + (1 << (pw - 1))][pw - 1];
}
void build() {
  for (int i = 1; i <= n; i++) P[i] = i;
  for (pw = 1; pw < L; pw++) {
    sort(P + 1, P + n + 1, cmp);
    Rank[P[1]][pw] = 1;
    for (int i = 2; i <= n; i++)
      Rank[P[i]][pw] = Rank[P[i - 1]][pw] + cmp(P[i - 1], P[i]);
  }
}
int lcp(int x, int y) {
  int res = 0;
  if (y < x) swap(x, y);
  if (x == 0) return 0;
  for (int i = L - 1; i >= 0; i--)
    if (y + (1 << i) <= n + 1 && Rank[x][i] == Rank[y][i])
      x += 1 << i, y += 1 << i, res += 1 << i;
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> n >> s;
  for (int i = 1; i <= n; i++) {
    Rank[i][0] = (s[i - 1] == '(' ? 1 : -1);
    ps[i] = ps[i - 1] + (s[i - 1] == '(' ? 1 : -1);
    vec[ps[i] + N].push_back(i);
  }
  build();
  ps[n + 1] = -inf;
  st.push(n + 1);
  for (int i = n; i >= 0; i--) {
    while (ps[i] <= ps[st.top()]) st.pop();
    nxt[i] = st.top();
    st.push(i);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    if (s[P[i] - 1] == '(')
      ans += max(
          0, (int)(lower_bound((vec[ps[P[i]] + N - 1]).begin(),
                               (vec[ps[P[i]] + N - 1]).end(), nxt[P[i] - 1]) -
                   lower_bound((vec[ps[P[i]] + N - 1]).begin(),
                               (vec[ps[P[i]] + N - 1]).end(),
                               P[i] + lcp(P[i - 1], P[i]))));
  cout << ans;
  return 0;
}
