func_code_string: #include <bits/stdc++.h>   using namespace std;   const int inf = 99999999;   struct seg_tree {     int seg[3 * 1000009], lazy[3 * 1000009];     void construct_segtree(int start, int end, int pos) {       lazy[pos] = -inf;       if (end == start + 1)         seg[pos] = 0;       else {         int mid = (start + end) / 2;         construct_segtree(start, mid, 2 * pos + 1);         construct_segtree(mid, end, 2 * pos + 2);         int t1 = seg[2 * pos + 1];         int t2 = seg[2 * pos + 2];         seg[pos] = t1 + t2;       }     }     int get_query(int ql, int qh, int low, int high, int pos) {       if (lazy[pos] != -inf) {         seg[pos] += lazy[pos];         if (high != low + 1) {           add_lazy(2 * pos + 1, lazy[pos]);           add_lazy(2 * pos + 2, lazy[pos]);         }         lazy[pos] = -inf;       }       if (qh <= low || ql >= high) return 0;       if (low >= ql && high <= qh) return seg[pos];       int mid = (low + high) / 2;       return get_query(ql, qh, low, mid, 2 * pos + 1) +              get_query(ql, qh, mid, high, 2 * pos + 2);     }     void update(int ql, int qh, int low, int high, int val, int pos) {       int mid = (high + low) / 2;       if (lazy[pos] != -inf) {         seg[pos] += lazy[pos];         if (high != low + 1) {           add_lazy(2 * pos + 1, lazy[pos]);           add_lazy(2 * pos + 2, lazy[pos]);         }         lazy[pos] = -inf;       }       if (qh <= low || ql >= high) return;       if (low >= ql && high <= qh) {         seg[pos] += val;         if (high != low + 1) {           add_lazy(2 * pos + 1, val);           add_lazy(2 * pos + 2, val);         }         return;       }       update(ql, qh, low, mid, val, 2 * pos + 1);       update(ql, qh, mid, high, val, 2 * pos + 2);       seg[pos] = seg[2 * pos + 1] + seg[2 * pos + 2];       return;     }       private:     void add_lazy(int place, int val) {       if (lazy[place] == -inf)         lazy[place] = val;       else         lazy[place] += val;     }   };   struct Query {     int first, second, indx;   };   int bin_search(int first, int second);   void pre_process();   void fn();   int comp(Query x, Query y);   int comp2(Query x, Query y);   seg_tree tree;   char input[1000009];   int arr[1000009], ans[1000009], n_q = 0;   Query q[1000009], open[1000009], close_here[1000009];   int my_stack[1000009];   int ten = 0;   int main() {     scanf( %s , input);     scanf( %d , &n_q);     for (int i = 0; i < n_q; i++) scanf( %d %d , &q[i].first, &q[i].second);     for (int i = 0; i < min(10, (int)strlen(input)); i++)       if (input[i] ==  ) ) ten++;     pre_process();     fn();     for (int i = 0; i < n_q; i++) printf( %d n , ans[i]);     return 0;   }   void fn() {     int closed = 0;     int y = strlen(input);     for (int i = 0; i <= max((int)y, 0) && closed < n_q; i++) {       while (closed < n_q && close_here[closed].second <= i) {         int k = close_here[closed].indx;         int indx = close_here[closed].indx;         ans[open[indx].indx] = tree.get_query(indx, indx + 1, 0, n_q, 0);         closed++;       }       if (n_q == closed) return;       if (i < y && input[i] ==  ) ) {         if (arr[i] != -1) {           int x = arr[i];           int indx = bin_search(x + 1, -inf);           if (indx != -1) tree.update(0, indx + 1, 0, n_q, 2, 0);         }       }     }   }   int bin_search(int first, int second) {     int s = 0, b = n_q, ret = -1;     while (b >= s) {       int mid = (b + s) / 2;       if (open[mid].first < first)         s = mid + 1, ret = max(ret, mid);       else         b = mid - 1;     }     return ret;   }   void pre_process() {     memset(arr, -1, sizeof(arr));     int stack_indx = 0;     for (int i = 0; i < strlen(input); i++) {       if (input[i] ==  ( )         my_stack[stack_indx++] = i;       else {         if (stack_indx) {           int x = my_stack[stack_indx - 1];           stack_indx--;           arr[i] = x;           arr[x] = i;         }       }     }     for (int i = 0; i < n_q; i++) q[i].first--;     for (int i = 0; i < n_q; i++) {       open[i].first = q[i].first;       open[i].second = q[i].second;       open[i].indx = i;     }     sort(open, open + n_q, comp);     for (int i = 0; i < n_q; i++) {       int k = open[i].indx;       q[k].indx = i;     }     for (int i = 0; i < n_q; i++) close_here[i] = q[i];     sort(close_here, close_here + n_q, comp2);     int prev = 0;     tree.construct_segtree(0, n_q, 0);   }   int comp(Query x, Query y) {     if (x.first == y.first) return x.second < y.second;     return x.first < y.first;   }   int comp2(Query x, Query y) {     if (x.second == y.second) return x.first < y.first;     return x.second < y.second;   }   