Problem: You are given a binary array A=(A_1,A_2,\cdots,A_N) of length N.

Process Q queries of the following types. The i-th query is represented by three integers T_i,L_i,R_i.

* T_i=1: Replace the value of A_j with 1-A_j for each L_i \leq j \leq R_i.
* T_i=2: Calculate the inversion(*) of the array A_{L_i},A_{L_i+1},\cdots,A_{R_i}．



Note：The inversion of the array x_1,x_2,\cdots,x_k is the number of the pair of integers i,j with 1 \leq i < j \leq k, x_i > x_j.

Constraints

* 1 \leq N \leq 2 \times 10^5
* 0 \leq A_i \leq 1
* 1 \leq Q \leq 2 \times 10^5
* 1 \leq T_i \leq 2
* 1 \leq L_i \leq R_i \leq N
* All values in Input are integer.

Input

Input is given from Standard Input in the following format:


N Q
A_1 A_2 \cdots A_N
T_1 L_1 R_1
T_2 L_2 R_2
\vdots
T_Q L_Q R_Q


Output

For each query with T_i=2, print the answer.

Example

Input

5 5
0 1 0 0 1
2 1 5
1 3 4
2 2 5
1 1 3
2 1 2


Output

2
0
1

Solution (in CPP):

Solution:
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void*wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class SVAL, class SFUN> struct segtree_rg{
  int N;
  int logN;
  SVAL*val;
  SFUN*fun;
  void malloc(int maxN, int once = 0){
    int i;
    for(i=1;i<maxN;i*=2){
      ;
    }
    val = new SVAL[2*i];
    fun = new SFUN[i];
    if(once){
      setN(maxN);
    }
  }
  void walloc(int maxN, int once = 0, void **mem = &wmem){
    int i;
    for(i=1;i<maxN;i*=2){
      ;
    }
    walloc1d(&val, 2*i, mem);
    walloc1d(&fun, i, mem);
    if(once){
      setN(maxN);
    }
  }
  void free(void){
    delete [] val;
    delete [] fun;
  }
  SVAL& operator[](int i){
    return val[N+i];
  }
  void setN(int n, int zerofill = 1, int dobuild = 1){
    int i;
    for(i=1,logN=0;i<n;i*=2,logN++){
      ;
    }
    N = i;
    if(dobuild){
      build();
    }
  }
  void build(void){
    int i;
    for(i=N-1;i;i--){
      segtree_rg_func(val[i], val[2*i], val[2*i+1]);
    }
    int jPV_0s1p = N;
    for(i=(1);i<(jPV_0s1p);i++){
      segtree_rg_id(fun[i]);
    }
  }
  inline void push_one(int a){
    if(2*a < N){
      segtree_rg_func(fun[2*a], fun[a], fun[2*a]);
    }
    segtree_rg_func(val[2*a], fun[a], val[2*a]);
    if(2*a+1 < N){
      segtree_rg_func(fun[2*a+1], fun[a], fun[2*a+1]);
    }
    segtree_rg_func(val[2*a+1], fun[a], val[2*a+1]);
    segtree_rg_id(fun[a]);
  }
  inline void push(int a){
    int i;
    for(i=logN;i;i--){
      push_one(a>>i);
    }
  }
  inline void build(int a){
    while(a > 1){
      a /= 2;
      segtree_rg_func(val[a], val[2*a], val[2*a+1]);
      segtree_rg_func(val[a], fun[a], val[a]);
    }
  }
  inline void change(int a, int b, SFUN f){
    int aa;
    int bb;
    if(a >= b){
      return;
    }
    aa = (a += N);
    bb = (b += N);
    push(a);
    push(b-1);
    if(a%2){
      segtree_rg_func(val[a], f, val[a]);
      a++;
    }
    if(b%2){
      b--;
      segtree_rg_func(val[b], f, val[b]);
    }
    a /= 2;
    b /= 2;
    while(a < b){
      if(a%2){
        segtree_rg_func(val[a], f, val[a]);
        segtree_rg_func(fun[a], f, fun[a]);
        a++;
      }
      if(b%2){
        b--;
        segtree_rg_func(val[b], f, val[b]);
        segtree_rg_func(fun[b], f, fun[b]);
      }
      a /= 2;
      b /= 2;
    }
    build(aa);
    build(bb-1);
  }
  inline SVAL get(int a, int b){
    SVAL res;
    SVAL tmp;
    int fga = 0;
    int fgb = 0;
    a += N;
    b += N;
    push(a);
    push(b-1);
    while(a < b){
      if(a%2){
        if(fga){
          segtree_rg_func(res, res, val[a]);
        }
        else{
          res = val[a];
          fga = 1;
        }
        a++;
      }
      if(b%2){
        b--;
        if(fgb){
          segtree_rg_func(tmp, val[b], tmp);
        }
        else{
          tmp = val[b];
          fgb = 1;
        }
      }
      a /= 2;
      b /= 2;
    }
    if(fga==1 && fgb==0){
      return res;
    }
    if(fga==0 && fgb==1){
      return tmp;
    }
    if(fga==1 && fgb==1){
      segtree_rg_func(res, res, tmp);
      return res;
    }
    return res;
  }
}
;
struct segval{
  int zero;
  int one;
  long long inv;
}
;
struct segfun{
  int r;
}
;
void segtree_rg_id(segfun &res){
  res.r = 0;
}
void segtree_rg_func(segval &res, segfun f, segval a){
  if(f.r){
    res.zero = a.one;
    res.one = a.zero;
    res.inv = (long long) a.one * a.zero - a.inv;
  }
  else{
    res = a;
  }
}
void segtree_rg_func(segval &res, segval a, segval b){
  res.zero = a.zero + b.zero;
  res.one = a.one + b.one;
  res.inv = a.inv + b.inv + (long long) a.one * b.zero;
}
void segtree_rg_func(segfun &res, segfun f, segfun g){
  res.r = f.r ^ g.r;
}
int N;
int Q;
int A[200000];
int T;
int L;
int R;
segtree_rg<segval, segfun> t;
int main(){
  int RZTsC2BF, i;
  wmem = memarr;
  segval v;
  segfun f;
  f.r = 1;
  rd(N);
  rd(Q);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  t.malloc(N);
  t.setN(N, 0, 0);
  for(i=(0);i<(N);i++){
    t[i].zero = 1 - A[i];
    t[i].one = A[i];
    t[i].inv = 0;
  }
  t.build();
  for(RZTsC2BF=(0);RZTsC2BF<(Q);RZTsC2BF++){
    rd(T);
    rd(L);L += (-1);
    rd(R);
    if(T==1){
      t.change(L, R, f);
    }
    else{
      v = t.get(L, R);
      wt_L(v.inv);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20200916-1

// --- original code ---
// struct segval{
//   int zero, one;
//   ll inv;
// };
// 
// struct segfun{
//   int r;
// };
// 
// void segtree_rg_id(segfun &res){
//   res.r = 0;
// }
// 
// void segtree_rg_func(segval &res, segfun f, segval a){
//   if(f.r){
//     res.zero = a.one;
//     res.one = a.zero;
//     res.inv = (ll) a.one * a.zero - a.inv;
//   } else {
//     res = a;
//   }
// }
// 
// void segtree_rg_func(segval &res, segval a, segval b){
//   res.zero = a.zero + b.zero;
//   res.one = a.one + b.one;
//   res.inv = a.inv + b.inv + (ll) a.one * b.zero;
// }
// 
// void segtree_rg_func(segfun &res, segfun f, segfun g){
//   res.r = f.r ^ g.r;
// }
// 
// int N, Q, A[2d5], T, L, R;
// segtree_rg<segval, segfun> t;
// {
//   segval v;
//   segfun f; f.r = 1;
// 
//   rd(N,Q,A(N));
//   t.malloc(N);
//   t.setN(N, 0, 0);
//   rep(i,N){
//     t[i].zero = 1 - A[i];
//     t[i].one = A[i];
//     t[i].inv = 0;
//   }
//   t.build();
//   rep(Q){
//     rd(T, L--, R);
//     if(T==1){
//       t.change(L, R, f);
//     } else {
//       v = t.get(L, R);
//       wt(v.inv);
//     }
//   }
// }