func_code_string: #include <bits/stdc++.h>   using namespace std;   string s;   vector<int> st;   const int N = 5010;   int pr[N], prefMinPlus[N], prefMinMinus[N];   int main() {     int ans = 0;     cin >> s;     for (size_t i = 0; i < s.size(); ++i) {       int cntq = 0;       st.clear();       int balance = 0, curPlusSum = 0, curMinusSum = 0;       prefMinMinus[i] = N;       prefMinPlus[i] = N;       for (size_t j = i; j < s.size(); ++j) {         if (s[j] ==  ? ) {           curPlusSum++;           curMinusSum--;           st.push_back(j);           cntq++;         } else if (s[j] ==  ( ) {           balance++;           curPlusSum++;           curMinusSum++;         } else {           balance--;           curPlusSum--;           curMinusSum--;         }         prefMinMinus[j + 1] = min(prefMinMinus[j], curMinusSum);         prefMinPlus[j + 1] = min(prefMinPlus[j], curPlusSum);         if ((cntq - balance) % 2 == 0) {           int cp = (cntq - balance) / 2;           int cm = cntq - cp;           if (cp >= 0 && cm >= 0) {             int minMinus = prefMinMinus[j + 1];             if (cp != 0) {               int pos = st[cp - 1];               int minPlus = prefMinPlus[pos + 1];               if (minPlus >= 0 && minMinus + cp * 2 >= 0) {                 ++ans;               }             } else if (minMinus >= 0) {               ++ans;             }           }         }       }     }     cout << ans <<   n ;     return 0;   }   