1. #include <cstdio>
    2. #include <algorithm>
    3. #include <cstring>
    4. #include <cstdlib>
    5. #include <cmath>
    6. #include <iostream>
    7. using namespace std;
    8. const int N = 50020;
    9. char S[N];
    10. int F[N],Flag[N];
    11. signed main()
    12. {
    13. #ifdef TSUKIAKIOI
    14. freopen("data.in","r",stdin);
    15. #endif
    16. F[0]=1;
    17. scanf("%s",S+1);
    18. int len = strlen(S+1);
    19. int ans = 0;
    20. for(int i=1;i<=len;++i){
    21. int tot=0,mar=0;
    22. for(int j=i;j<=len;++j){ // check how many [i,j] is a perfect section
    23. if(S[j] == '(') tot++;
    24. if(S[j] == ')') tot--;
    25. if(S[j] == '?') mar++,tot--;
    26. // 一个括号序列合法的必要条件:任意前缀左括号个数不少于右括号
    27. // 充要条件 : 条件(1) + 左括号个数 == 右括号个数
    28. // ()
    29. if(tot<0 && mar>0){
    30. tot+=2;
    31. mar--;
    32. }
    33. if(tot<0)
    34. break;
    35. if(tot == 0)
    36. ans++;
    37. }
    38. }
    39. printf("%d\n",ans);
    40. return 0;
    41. }