func_code_string: #include <bits/stdc++.h>   #pragma GCC optimize( -O3 )   using namespace std;   void _main();   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     _main();   }   const int inf = INT_MAX / 2;   const long long infl = 1LL << 60;   template <class T>   bool chmax(T &a, const T &b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool chmin(T &a, const T &b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   string E;   int P, M;   struct Node {     Node *left, *right;     int value, id, cnt;   };   int i = 0, idx = 0;   Node *parse() {     Node *n = new Node;     n->id = idx;     idx++;     if (E[i] ==  ( ) {       i++;       n->left = parse();       i++;       n->right = parse();       i++;       n->value = -1;       n->cnt = n->left->cnt + n->right->cnt + 1;     } else {       n->value = E[i] -  0 ;       i++;       n->cnt = 0;     }     return n;   }   int vis[4101][105];   pair<int, int> memo[4101][105];   pair<int, int> f(Node *n, int p) {     int m = n->cnt - p;     if (m < 0) return {inf, inf};     int id = n->id;     if (vis[id][p]) return memo[id][p];     if (n->cnt == 0) return memo[id][p] = {n->value, n->value};     int mi = inf, ma = -inf;     for (int pls = 0; pls < p; pls++) {       auto le = f(n->left, pls);       if (le.first == inf) continue;       auto ri = f(n->right, p - pls - 1);       if (ri.first == inf) continue;       vector<int> a = {le.first, le.second};       vector<int> b = {ri.first, ri.second};       for (int i = 0; i < 2; i++)         for (int j = 0; j < 2; j++) {           int res = a[i] + b[j];           chmin(mi, res);           chmax(ma, res);         }     }     for (int pls = 0; pls < p + 1; pls++) {       auto le = f(n->left, pls);       if (le.first == inf) continue;       auto ri = f(n->right, p - pls);       if (ri.first == inf) continue;       vector<int> a = {le.first, le.second};       vector<int> b = {ri.first, ri.second};       for (int i = 0; i < 2; i++)         for (int j = 0; j < 2; j++) {           int res = a[i] - b[j];           chmin(mi, res);           chmax(ma, res);         }     }     assert(mi != inf);     vis[id][p] = 1;     return memo[id][p] = {mi, ma};   }   pair<int, int> g(Node *n, int p) {     int m = n->cnt - p;     if (m < 0) return {inf, inf};     int id = n->id;     if (vis[id][p]) return memo[id][p];     if (n->cnt == 0) return memo[id][p] = {n->value, n->value};     int mi = inf, ma = -inf;     for (int pls = 0; pls < p; pls++) {       auto le = g(n->left, pls);       if (le.first == inf) continue;       auto ri = g(n->right, p - pls - 1);       if (ri.first == inf) continue;       vector<int> a = {le.first, le.second};       vector<int> b = {ri.first, ri.second};       for (int i = 0; i < 2; i++)         for (int j = 0; j < 2; j++) {           int res = a[i] - b[j];           chmin(mi, res);           chmax(ma, res);         }     }     for (int pls = 0; pls < p + 1; pls++) {       auto le = g(n->left, pls);       if (le.first == inf) continue;       auto ri = g(n->right, p - pls);       if (ri.first == inf) continue;       vector<int> a = {le.first, le.second};       vector<int> b = {ri.first, ri.second};       for (int i = 0; i < 2; i++)         for (int j = 0; j < 2; j++) {           int res = a[i] + b[j];           chmin(mi, res);           chmax(ma, res);         }     }     assert(mi != inf);     vis[id][p] = 1;     return memo[id][p] = {mi, ma};   }   void _main() {     cin >> E >> P >> M;     E +=  = ;     Node *root = parse();     if (P <= M) {       auto res = f(root, P);       int ans = res.second;       cout << ans << endl;     } else {       auto res = g(root, M);       int ans = res.second;       cout << ans << endl;     }   }   