#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
short val[2][N][N];
short mn[2][N][N];
string s;
int n;
int main() {
  cin >> s;
  s = " " + s;
  n = s.size();
  int out = 0;
  for (int l = 1; l < n; l++) {
    for (int r = l; r < n; r++) {
      if (s[r] == '(') {
        val[0][l][r] = val[0][l][r - 1] + 1;
        val[1][l][r] = val[1][l][r - 1] + 1;
      }
      if (s[r] == ')') {
        val[0][l][r] = val[0][l][r - 1] - 1;
        val[1][l][r] = val[1][l][r - 1] - 1;
      }
      if (s[r] == '?') {
        val[0][l][r] = val[0][l][r - 1] + 1;
        val[1][l][r] = val[1][l][r - 1] - 1;
      }
      mn[0][l][r] = min(val[0][l][r], mn[0][l][r - 1]);
      mn[1][l][r] = min(val[1][l][r], mn[1][l][r - 1]);
    }
  }
  for (int l = 1; l < n; l++) {
    int cnto = 0, cntc = 0, cntm = 0;
    vector<int> indices;
    for (int r = l; r < n; r++) {
      if (s[r] == '(') cnto++;
      if (s[r] == ')') cntc++;
      if (s[r] == '?') cntm++, indices.push_back(r);
      if ((r - l + 1) % 2) continue;
      if (cnto + cntm < cntc || cntc + cntm < cnto) continue;
      int rc = (r - l + 1) / 2;
      if (cnto == rc && cntc == rc) {
        if (mn[0][l][r] == 0 && val[0][l][r] == 0) out++;
      } else if (cnto == rc) {
        if (mn[1][l][r] == 0 && val[1][l][r] == 0) out++;
      } else if (cntc == rc) {
        if (mn[0][l][r] == 0 && val[0][l][r] == 0) out++;
      } else {
        int i = indices[(r - l + 1) / 2 - cnto - 1];
        if (mn[0][l][i] >= 0 && val[0][l][i] + mn[1][i + 1][r] >= 0) out++;
      }
    }
  }
  cout << out;
}
