#include <cstdio>#include <algorithm>#include <cstring>#include <cstdlib>#include <cmath>#include <iostream>using namespace std;const int N = 50020;char S[N];int F[N],Flag[N];signed main(){#ifdef TSUKIAKIOI freopen("data.in","r",stdin);#endif F[0]=1; scanf("%s",S+1); int len = strlen(S+1); int ans = 0; for(int i=1;i<=len;++i){ int tot=0,mar=0; for(int j=i;j<=len;++j){ // check how many [i,j] is a perfect section if(S[j] == '(') tot++; if(S[j] == ')') tot--; if(S[j] == '?') mar++,tot--; // 一个括号序列合法的必要条件:任意前缀左括号个数不少于右括号 // 充要条件 : 条件(1) + 左括号个数 == 右括号个数 // () if(tot<0 && mar>0){ tot+=2; mar--; } if(tot<0) break; if(tot == 0) ans++; } } printf("%d\n",ans); return 0;}