#include <bits/stdc++.h>
using namespace std;
template <class c1>
ostream& _out(ostream& ost, c1 a, c1 b);
template <class... Types>
ostream& operator<<(ostream& out, const tuple<Types...>& value);
template <class T1, class T2>
ostream& operator<<(ostream& ost, const pair<T1, T2>& _cnt);
template <class T1>
ostream& operator<<(ostream& ost, const vector<T1>& _cnt) {
  return _out(ost, _cnt.begin(), _cnt.end());
};
template <class T1>
ostream& operator<<(ostream& ost, const deque<T1>& _cnt) {
  return _out(ost, _cnt.begin(), _cnt.end());
};
template <class T1>
ostream& operator<<(ostream& ost, const list<T1>& _cnt) {
  return _out(ost, _cnt.begin(), _cnt.end());
};
template <class T1, class T2>
ostream& operator<<(ostream& ost, const set<T1, T2>& _cnt) {
  return _out(ost, _cnt.begin(), _cnt.end());
};
template <class T1, class T2>
ostream& operator<<(ostream& ost, const multiset<T1, T2>& _cnt) {
  return _out(ost, _cnt.begin(), _cnt.end());
};
template <class T1, class T2, class T3>
ostream& operator<<(ostream& ost, const map<T1, T2, T3>& _cnt) {
  return _out(ost, _cnt.begin(), _cnt.end());
};
template <class T1, class T2, class T3>
ostream& operator<<(ostream& ost, const multimap<T1, T2, T3>& _cnt) {
  return _out(ost, _cnt.begin(), _cnt.end());
};
template <class T1, class T2>
ostream& operator<<(ostream& ost, const pair<T1, T2>& _cnt) {
  return ost << '(' << _cnt.first << ", " << _cnt.second << ')';
}
template <class T1>
ostream& _out(ostream& ost, T1 a, T1 b) {
  ost << '{';
  if (a != b) {
    ost << *a;
    while (++a != b) ost << ", " << *a;
  }
  return ost << '}';
}
template <class Type, unsigned N, unsigned Last>
struct tuple_printer {
  static void print(ostream& out, const Type& value) {
    out << get<N>(value) << ", ";
    tuple_printer<Type, N + 1, Last>::print(out, value);
  }
};
template <class Type, unsigned N>
struct tuple_printer<Type, N, N> {
  static void print(ostream& out, const Type& value) { out << get<N>(value); }
};
template <class... Types>
ostream& operator<<(ostream& out, const tuple<Types...>& value) {
  out << '(';
  tuple_printer<tuple<Types...>, 0, sizeof...(Types) - 1>::print(out, value);
  out << ')';
  return out;
}
vector<string> _split(const string& s, char c) {
  int br = 0;
  vector<string> v(1);
  for (int i = 0; i < (((int)(s).size())); ++i) {
    if (s[i] == '[' || s[i] == '(' || s[i] == '{')
      br++;
    else if (s[i] == ']' || s[i] == ')' || s[i] == '}')
      br--;
    if (s[i] == c && br == 0)
      v.push_back("");
    else
      v.back().push_back(s[i]);
  }
  return v;
}
template <class T1>
void _err(string del, vector<string>::iterator it, T1 a) {
  bool wb = (*it)[0] == ' ', we = (*it).back() == ' ';
  cerr << it->substr(wb, ((int)(*it).size()) - wb - we) << " = " << a << '\n';
  (void)del;
}
template <class T1, class... Args>
void _err(string del, vector<string>::iterator it, T1 a, Args... args) {
  bool wb = (*it)[0] == ' ', we = (*it).back() == ' ';
  cerr << it->substr(wb, ((int)(*it).size()) - wb - we) << " = " << a << del;
  _err(del, ++it, args...);
}
template <class T>
T maxx(const T& a) {
  return a;
}
template <class T, class... Args>
T maxx(const T& a, Args... args) {
  return max(a, maxx(args...));
}
template <class T>
T minn(const T& a) {
  return a;
}
template <class T, class... Args>
T minn(const T& a, Args... args) {
  return min(a, minn(args...));
}
string s;
int sa[500010], pos[500010], lcp[500010], tmp[500010];
int N = 1 << 19;
pair<int, int> MIN[1 << 20];
int gap;
bool comp(int a, int b) {
  if (pos[a] != pos[b]) return pos[a] < pos[b];
  a += gap;
  b += gap;
  return (a < ((int)(s).size()) && b < ((int)(s).size())) ? pos[a] < pos[b]
                                                          : a > b;
}
void calcSA() {
  for (int i = 0; i < (((int)(s).size())); ++i) sa[i] = i, pos[i] = s[i];
  gap = 1;
  while (true) {
    sort(sa, sa + ((int)(s).size()), comp);
    for (int i = 0; i < (((int)(s).size()) - 1); ++i)
      tmp[i + 1] = tmp[i] + comp(sa[i], sa[i + 1]);
    for (int i = 0; i < (((int)(s).size())); ++i) pos[sa[i]] = tmp[i];
    if (tmp[((int)(s).size()) - 1] == ((int)(s).size()) - 1) break;
    gap *= 2;
  }
}
void calcLCP() {
  int x = 0;
  for (int i = 0; i < (((int)(s).size())); ++i) {
    if (pos[i] == ((int)(s).size()) - 1) continue;
    while (s[i + x] == s[sa[pos[i] + 1] + x]) x++;
    lcp[pos[i]] = x;
    if (x) x--;
  }
}
pair<int, int> getMIN(const pair<int, int>& a, const pair<int, int>& b) {
  if (a.first == b.first) return make_pair(a.first, a.second + b.second);
  return min(a, b);
}
void initTree() {
  for (int i = (N); i <= (N + ((int)(s).size()) - 1); ++i)
    MIN[i] = make_pair(MIN[i - 1].first + (s[i - N] == '(' ? 1 : -1), 1);
  for (int i = (N - 1); i >= (1); --i)
    MIN[i] = getMIN(MIN[i << 1], MIN[(i << 1) + 1]);
}
int getNegPos(int a, int zero) {
  while (a < N) MIN[a << 1].first < zero ? a <<= 1 : a = (a << 1) + 1;
  return a - N;
}
int getNeg(int a, int b) {
  int zero = MIN[a + N].first - (s[a] == '(' ? 1 : -1);
  a += N;
  b += N;
  if (MIN[a].first < zero) return getNegPos(a, zero);
  int r_pos = b + (MIN[b].first >= zero);
  while (a + 1 < b) {
    if (~a & 1 && MIN[a + 1].first < zero) return getNegPos(a + 1, zero);
    if (b & 1 && MIN[b - 1].first < zero) r_pos = b - 1;
    a >>= 1;
    b >>= 1;
  }
  return getNegPos(r_pos, zero);
}
int getCorrect(int a, int b, int zero) {
  if (b < a) return 0;
  a += N;
  b += N;
  int res = MIN[a].first == zero;
  if (a != b) res += MIN[b].first == zero;
  while (a + 1 < b) {
    if (~a & 1 && MIN[a + 1].first == zero) res += MIN[a + 1].second;
    if (b & 1 && MIN[b - 1].first == zero) res += MIN[b - 1].second;
    a >>= 1;
    b >>= 1;
  }
  return res;
}
int getRes(int beg, int l) {
  return getCorrect(beg + l, getNeg(beg, ((int)(s).size()) - 1) - 1,
                    MIN[beg + N].first - (s[beg] == '(' ? 1 : -1));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  int n;
  cin >> n >> s;
  N = 1 << (sizeof(n) * 8 - __builtin_clz(n - 1));
  calcSA();
  calcLCP();
  initTree();
  long long res = getRes(sa[0], 0);
  for (int i = (1); i <= (((int)(s).size()) - 1); ++i)
    res += getRes(sa[i], lcp[i - 1]);
  cout << res << '\n';
  return 0;
}
