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 <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

using namespace std;
typedef long long ll;

struct node{
    ll n, cnt, inv;
};

node unit_node = (node){-100, -100, -100};

node merge_node(node a, node b){
    if(a.n == -100) return b;
    if(b.n == -100) return a;
    return (node){a.n+b.n, a.cnt+b.cnt, a.inv+b.inv+a.cnt*(b.n-b.cnt)};
}

node inv_node(node a){
    if(a.n == -100) return a;
    return (node){a.n, a.n-a.cnt, (a.cnt*(a.n-a.cnt))-a.inv};
}

template <typename T, typename S>
struct LazySegmentTree {
    int n;
    T unit;
    vector<T> node;
    vector<S> lazy;
    vector<bool> lazyFlag;

    T calc(T a, T b){
        T ans;
        ans = merge_node(a, b); //適宜変える
        return ans;
    }

    S calcLazy(S a, S b){
        S ans;
        ans = a^b; //適宜変える
        return ans;
    }

    S propagateLazy(S lazy1, S lazy2){
        return lazy1^lazy2; //適宜変える
    }

    T merge(T node, S lazy){
        if(lazy) return inv_node(node);
        return node; //適宜変える
    }

    S clearLazy(){
        return false; //適宜変える
    }

    LazySegmentTree(vector<T> v, T UNIT) {
        int sz = (int)v.size();
        unit = UNIT;
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, unit);
        lazy.resize(2*n-1, false);
        lazyFlag.resize(2*n-1, false);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = calc(node[i*2+1], node[i*2+2]);
    }

    void lazyEvaluate(int k, int l, int r) {
        if(lazyFlag[k]) {
            node[k] = merge(node[k], lazy[k]);
            if(r - l > 1) {
                lazy[k*2+1] = propagateLazy(lazy[k*2+1], lazy[k]);
                lazy[k*2+2] = propagateLazy(lazy[k*2+2], lazy[k]);
                lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
            }
            lazyFlag[k] = false;
            lazy[k] = clearLazy();
        }
    }

    //[a, b)
    //区間[a, b]への更新に対してはupdate(a, b+1, x)と呼ぶ
    void update(int a, int b, S x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = calcLazy(lazy[k], x);
            lazyFlag[k] = true;
            lazyEvaluate(k, l, r);
        }
        else {
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = calc(node[2*k+1], node[2*k+2]);
        }
    }

    //[a, b)
    //区間[a, b]へのクエリに対してはquery(a, b+1)と呼ぶ
    T query(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return unit;
        if(a <= l && r <= b) return node[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return calc(vl, vr);
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N, Q; cin >> N >> Q;
    vector<node> v;
    for(int i = 0; i < N; i++){
        int a; cin >> a;
        if(a == 0){
            node n = (node){1, 0, 0};
            v.push_back(n);
        }else{
            node n = (node){1, 1, 0};
            v.push_back(n);
        }
    }
    LazySegmentTree<node, bool> sgt(v, unit_node);
    
    for(int i = 0; i < Q; i++){
        int t, l, r; cin >> t >> l >> r;
        if(t == 1){
            sgt.update(l-1, r, true);
        }else{
            cout << sgt.query(l-1, r).inv << endl;
        }
    }
}