#include <bits/stdc++.h>
using namespace std;
int n;
char s[5010];
int ans;
int dp1[5010], dp2[5010];
int min1[5010][5010], min2[5010][5010];
vector<int> pos;
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    if (s[i] == ')')
      dp1[i] = dp1[i - 1] - 1;
    else
      dp1[i] = dp1[i - 1] + 1;
    if (s[i] == '(')
      dp2[i] = dp2[i - 1] + 1;
    else
      dp2[i] = dp2[i - 1] - 1;
    if (s[i] == '?') pos.push_back(i);
  }
  for (int l = 1; l <= n; l++) {
    for (int r = l; r <= n; r++) {
      if (l == r) {
        min1[l][r] = dp1[l] - dp1[l - 1];
        min2[l][r] = dp2[l] - dp2[l - 1];
      } else {
        min1[l][r] = min(min1[l][r - 1], dp1[r] - dp1[l - 1]);
        min2[l][r] = min(min2[l][r - 1], dp2[r] - dp2[l - 1]);
      }
    }
  }
  for (int l = 1; l <= n; l++) {
    int cnt1 = 0, cnt2 = 0;
    int p = lower_bound(pos.begin(), pos.end(), l) - pos.begin();
    for (int r = l; r <= n; r++) {
      if (s[r] == '(') cnt1++;
      if (s[r] == ')') cnt2++;
      if ((r - l + 1) & 1) continue;
      int now = (r - l + 1 - 2 * cnt1) / 2;
      if (now < 0 || r - l + 1 - cnt1 - cnt2 - now < 0) continue;
      if (!now) {
        if (min2[l][r] >= 0) ans++;
        continue;
      }
      int t = pos[p + now - 1];
      if (min1[l][t] >= 0 && dp1[t] - dp1[l - 1] + min2[t + 1][r] >= 0) ans++;
    }
  }
  printf("%d", ans);
  getchar();
  getchar();
  return 0;
}
