func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 1;   struct node {     int ans = 0;     int o = 0;     int c = 0;     node() : ans(0), o(0), c(0) {}     node(int x) : ans(0), o((x == 1 ? 1 : 0)), c((x == 1 ? 0 : 1)) {}   };   node t[2 * MAX];   int n;   node combine(node x, node y) {     node cur;     int t = min(x.o, y.c);     cur.ans = t + x.ans + y.ans;     cur.o = x.o + y.o - t;     cur.c = x.c + y.c - t;     return cur;   }   int query(int l, int r) {     node resl, resr;     for (l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1) resl = combine(resl, t[l++]);       if (r & 1) resr = combine(t[--r], resr);     }     return combine(resl, resr).ans;   }   int main() {     string s;     cin >> s;     n = s.length();     for (int i = 0; i < n; i++) {       int ch = (s[i] ==  (  ? 1 : 0);       t[i + n] = node(ch);     }     for (int i = n - 1; i > 0; i--) {       int x = i << 1;       int y = i << 1 | 1;       if (x > y) {         t[i] = combine(t[y], t[x]);       } else {         t[i] = combine(t[x], t[y]);       }     }     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int l, r;       scanf( %d%d , &l, &r);       printf( %d n , query(l - 1, r) * 2);     }     return 0;   }   