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:
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>


#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;

ll modd = 1000 * 1000 * 1000 + 7;

template<class T>
class SegmentTree2 {
    public:
     
      SegmentTree2(const vector<T>& data, function<T(T,T)> f_, T zero_value = 0) : zv(zero_value), f(f_) {   
          Initialize(data);
      }

      SegmentTree2(int n, function<T(T,T)> f_, T zero_value = 0) : zv(zero_value), f(f_) {
          vector<T> temp(n, zv);
          Initialize(temp);
      }

      T operator[](int i) {
          return tree[B+i];
      }

      T GetEvaluation(int L, int R) {   // "min/max" on interval [L,R); 0-based indexing, as usual
        if (R<=L) {  return zv;  }
        return GetEvaluationHelper(L, R, 0, B, 1);
      }


      void SetVal(int i, T val) {
			tree[B+i] = val;
			for(int j = (B + i) / 2; j >= 1; j /= 2) {
				tree[j] = f(tree[2*j], tree[2*j+1]);
			}
      }

      private:
        vector<T> tree;
        int B;  // power of two greater than size of input data
        T zv;
        function<T(T,T)> f;

        void Initialize(const vector<T>& data) {
    	  B = 1;
          while(B < data.size()) {B *= 2;  }
          tree = std::move(vector<T>(2*B, zv));
          copy(data.begin(), data.end(), next(tree.begin(), B));
          for(int i = B - 1; i >= 1; --i) {
  	  	     tree[i] = f(tree[2*i], tree[2*i+1]);
          }
        }

      T GetEvaluationHelper(int L, int R, int start, int length, int tree_index) {
          if (L==R) {  return zv; }
          if ((L==start) && (R==start+length)) {   return tree[tree_index];  }
          int midpoint = start + length/2;

          T left_ = zv, right_ = zv;
          if (L<=min(midpoint,R)) {
            left_ = GetEvaluationHelper(L, min(midpoint,R), start, length/2, 2*tree_index);
          }
          if (max(midpoint,L)<=R) {
            right_ = GetEvaluationHelper(max(midpoint,L), R, midpoint, length/2, 2*tree_index+1);
          }
          return f(left_, right_);
      }

};


template<class T, class S>
class LazySegmentTree {
    // Lazy propagation segment tree, containing elts of type T; S is type ("paramter space type") for all possible function we'll be
    // applying to elts (thee funcs should commute with f; f should be associative)
    public:
      typedef function<T(T)> application_type;
     
      // f is combining function, should be associative; zero_value is identity for f as a grupoid operation;
      // com is composition of application functions, specifically com(a1, a2) is a1 \circ a2 ie com(a1,a2)(t)=a1(a2(t))
      // param is parametrization of application functions
      // id_ is parameter for identity application function
      // typical example if you have min segtree, and you want to assign values in a lazy way to interval:
      // T=int,S=int, f(x,y) = min(x,y), zero_value = +infty"=modd"; com(a,b)=a; 
      // param(a) = [](int a){ return function<int(int)>([](int x){return a;}); }
      // id_ = say modd+1; and param(modd+1) should be identity, and comm should accomodate that
      
      LazySegmentTree(const vector<T>& data, function<T(T,T)> f_, T zero_value,
        function<S(S,S)> com, function<application_type(S)> param, S id_) : zv(zero_value), f(f_), composition(com),
            paramtrization(param), ident(id_) {   
          Initialize(data);
      }

      T operator[](int i) {
          return GetEvaluation(i, i+1);
      }

      T GetEvaluation(int L, int R) {   // "min/max" on interval [L,R); 0-based indexing, as usual
        if (R<=L) {  return zv;  }
        return GetEvaluationHelper(L, R, 0, B, 1, ident);
      }

      void SetVal(int L, int R, S g) {
          if (R<=L) {  return;  }
          SetValHelper(L, R, 0, B, 1, g);
      }

      private:
        vector<T> tree;
        vector<S> application_function_below;
        int B;  // power of two greater than size of input data
        T zv;
        function<T(T,T)> f;
        function<S(S,S)> composition;
        function<application_type(S)> paramtrization;
        S ident;

        void Initialize(const vector<T>& data) {
    	  B = 1;
          while(B < data.size()) {B *= 2;  }
          tree = vector<T>(2*B, zv);
          copy(data.begin(), data.end(), next(tree.begin(), B));
          for(int i = B - 1; i >= 1; --i) {
  	  	     tree[i] = f(tree[2*i], tree[2*i+1]);
          }
          application_function_below = vector<T>(2*B, ident);
        }

      T GetEvaluationHelper(int L, int R, int start, int length, int tree_index, S accumulate) {
          if (L==R) {  return zv; }
          if ((L==start) && (R==start+length)) {   return paramtrization(accumulate)(tree[tree_index]);  }
          int midpoint = start + length/2;
          T left_ = zv, right_ = zv;

          if (L<=min(midpoint,R)) {
            left_ = GetEvaluationHelper(L, min(midpoint,R), start, length/2, 2*tree_index, composition(accumulate, application_function_below[tree_index]));
          }
          if (max(midpoint,L)<=R) {
            right_ = GetEvaluationHelper(max(midpoint,L), R, midpoint, length/2, 2*tree_index+1, composition(accumulate, application_function_below[tree_index]));
          }
          return f(left_, right_);
      }

      void SetValHelper(int L, int R, int start, int length, int tree_index, S g) {
          if (L==R) {  return; }
          if ((L==start) && (R==start+length)) {
              tree[tree_index] = paramtrization(g)(tree[tree_index]);
              application_function_below[tree_index] = composition(g, application_function_below[tree_index]);
              return;  }
          int midpoint = start + length/2;
          application_function_below[2*tree_index] = composition(application_function_below[tree_index], application_function_below[2*tree_index]);
          application_function_below[2*tree_index+1] = composition(application_function_below[tree_index], application_function_below[2*tree_index+1]);
          tree[2*tree_index] = paramtrization(application_function_below[tree_index])(tree[2*tree_index]);
          tree[2*tree_index+1] = paramtrization(application_function_below[tree_index])(tree[2*tree_index+1]);
          application_function_below[tree_index] = ident;

          if (L<=min(midpoint,R)) {
            SetValHelper(L, min(midpoint,R), start, length/2, 2*tree_index, g);
          }
          if (max(midpoint,L)<=R) {
            SetValHelper(max(midpoint,L), R, midpoint, length/2, 2*tree_index+1, g);
          }
          tree[tree_index] = f(tree[2*tree_index], tree[2*tree_index+1]);
      }

};


int main()   {

      ios_base::sync_with_stdio(false);

      cout.precision(17);
      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
      uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no


//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n); readint(q);
        vector<ll> a, b;
        forr(i,0,n) {
            readint(aa); 
            if (aa==0) {aa = -1;}            
            a.push_back(aa);
            b.push_back(i*aa);
        }
        LazySegmentTree<ll, ll> seg_lazy(a, 
           [](ll x, ll y) { return x+y; }, 
           0, [](ll x, ll y) {
               return x*y;
           }, 
           [](ll line) {  return [line](ll x) {  return line*x; };  },
            1
        );
        LazySegmentTree<ll, ll> seg_lazy2(b, 
           [](ll x, ll y) { return x+y; }, 
           0, [](ll x, ll y) {
               return x*y;
           }, 
           [](ll line) {  return [line](ll x) {  return line*x; };  },
            1
        );
       
        forr(i,0,q) {
            readint(aa); readll(l); readll(r); l--;
            if(aa==1) {
                seg_lazy.SetVal(l,r,-1);
                seg_lazy2.SetVal(l,r,-1);
            }
            if (aa==2) {
                ll s1 = seg_lazy.GetEvaluation(l, r);
                ll s2 = seg_lazy2.GetEvaluation(l, r);
                ll nn = r-l;
                ll ss = (nn*(nn-1))/2 - (s1*s1-nn)/2 + s1*(nn-1) - 2*(s2-l*s1);
                cout << ss/4 << endl;
            }
        }
    }
    return 0;
}