func_code_string: #include <bits/stdc++.h>   using namespace std;   struct BIT {     int a[400010], size, n, dl, dr, dir, len;     inline void set(int x, int v) {       int k = v - query(x, x);       for (; x <= size; x += ((x) & (-(x)))) a[x] += k;     }     inline void add(int x, int v) {       for (; x <= size; x += ((x) & (-(x)))) a[x] += v;     }     inline int query(int x) {       int res = 0;       for (; x; x -= ((x) & (-(x)))) res += a[x];       return res;     }     inline int query(int l, int r) { return query(r) - query(l - 1); }     inline void ope1(int x) {       if (x > len - x) dir = -dir, x = len - x;       if (dir == 1) {         dl += x;         for (int i = 1; i <= x; i++) {           add(dl + i, query(dl - i + 1, dl - i + 1));           set(dl - i + 1, 0);         }       } else {         dr += x;         for (int i = 1; i <= x; i++) {           add(n - (dr + i) + 1, query(n - (dr - i), n - (dr - i)));           set(n - (dr - i), 0);         }       }       len = max(x, len - x);     }     inline void ope2(int l, int r) {       if (dir == 1)         printf( %d n , query(l + dl + 1, r + dl));       else         printf( %d n , query(n - dr - r + 1, n - dr - l));     }     void init(int N) {       for (size = 1; size < N; size <<= 1)         ;       dl = dr = 0, dir = 1, len = n = N;       for (int i = 1; i <= n; i++) set(i, 1);     }     void debug() {       printf( =============== n );       for (int i = 1; i <= n; i++) printf( %d  , query(i, i));       printf(  n );     }   } a;   int n, q;   int main() {     scanf( %d%d , &n, &q);     a.init(n);     for (int i = 1, ope, l, r, p; i <= q; i++) {       scanf( %d , &ope);       if (ope == 1) {         scanf( %d , &p);         a.ope1(p);       } else {         scanf( %d%d , &l, &r);         a.ope2(l, r);       }     }     return 0;   }   