#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e3 + 7;
const int MOD = (int)1e9 + 7;
string s;
int n;
bool dp[N + N];
short closed[N][N];
short open[N][N];
short prebal[N][N];
int main() {
  cin >> s;
  n = s.size();
  for (int l = 0; l < n; l++) {
    short bal = 0;
    for (int r = l; r < n; r++) {
      if (s[r] == '(') ++bal;
      if (s[r] == ')') --bal;
      if (s[r] == '?') --bal;
      if (l == r)
        closed[l][r] = bal;
      else
        closed[l][r] = min(bal, closed[l][r - 1]);
    }
  }
  for (int l = 0; l < n; l++) {
    short bal = 0;
    for (int r = l; r < n; r++) {
      if (s[r] == '(') ++bal;
      if (s[r] == ')') --bal;
      if (s[r] == '?') ++bal;
      if (l == r)
        open[l][r] = bal;
      else
        open[l][r] = min(bal, open[l][r - 1]);
      prebal[l][r] = bal;
    }
  }
  int ans = 0;
  for (int l = 0; l < n; l++) {
    int bal = 0;
    int mark = 0;
    vector<int> marked;
    for (int r = l; r < n; r++) {
      if (s[r] == '(') ++bal;
      if (s[r] == ')') --bal;
      if (s[r] == '?') {
        mark++;
        marked.push_back(r);
      }
      if ((mark - bal) % 2 != 0) continue;
      int o = (mark - bal) / 2;
      if (o < 0 || o > mark) continue;
      int c = mark - o;
      int pos = l - 1;
      if (o) pos = marked[o - 1];
      int minbal = 0;
      if (pos >= l) minbal = open[l][pos];
      if (pos + 1 <= r)
        minbal =
            min(minbal, closed[pos + 1][r] + (pos >= l ? prebal[l][pos] : 0));
      if (minbal < 0) {
        continue;
      }
      ++ans;
    }
  }
  cout << ans;
  return 0;
}
