func_code_string: #include <bits/stdc++.h>   using namespace std;   struct data {     int le, ri, cnt;     data(int le_ = 0, int ri_ = 0, int cnt_ = 0) {       le = le_;       ri = ri_;       cnt = cnt_;     }   };   const int N = 1e6 + 10;   int seg[4 * N + 10];   int brk[5][4 * N + 10];   int n;   void add(int idx, bool b, int L = 0, int R = n, int id = 1) {     if (L == R - 1) {       brk[b][id]++;       return;     }     int mid = (L + R) / 2;     if (idx < mid)       add(idx, b, L, mid, 2 * id + 0);     else       add(idx, b, mid, R, 2 * id + 1);     seg[id] = seg[2 * id + 0] + seg[2 * id + 1] +               min(brk[0][2 * id + 0], brk[1][2 * id + 1]);     brk[0][id] =         brk[0][2 * id + 1] + max(0, brk[0][2 * id + 0] - brk[1][2 * id + 1]);     brk[1][id] =         brk[1][2 * id + 0] + max(0, brk[1][2 * id + 1] - brk[0][2 * id + 0]);     return;   }   data get(int l, int r, int L = 0, int R = n, int id = 1) {     if (L == l && R == r) return data(brk[0][id], brk[1][id], seg[id]);     int mid = (L + R) / 2;     data le, ri;     if (l < mid) le = get(l, min(r, mid), L, mid, 2 * id + 0);     if (r > mid) ri = get(max(l, mid), r, mid, R, 2 * id + 1);     data ret;     ret.cnt = le.cnt + ri.cnt + min(le.le, ri.ri);     ret.le = ri.le + max(0, le.le - ri.ri);     ret.ri = le.ri + max(0, ri.ri - le.le);     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     string s;     cin >> s, n = s.size();     for (int i = 0; i < s.size(); i++)       if (s[i] ==  ( )         add(i, 0);       else         add(i, 1);     int q;     cin >> q;     while (q--) {       int l, r;       cin >> l >> r, l--;       cout << 2 * get(l, r).cnt << endl;     }     return 0;   }   