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 <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template<typename Monoid, typename OperatorMonoid = Monoid>
struct LazySegmentTree{
    using F = function<Monoid(Monoid, Monoid)>;
    using G = function<Monoid(Monoid, OperatorMonoid)>;
    using H = function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;
    using C = function<OperatorMonoid(OperatorMonoid, int)>;

    int sz;
    vector<Monoid> data;
    vector<OperatorMonoid> lazy;
    const F f;
    const G g;
    const H h;
    const Monoid M1;            // モノイドの単位元
    const OperatorMonoid OM0;   // 作用素モノイドの単位元
    const C c;

    LazySegmentTree(int n, const F f, const G g, const H h, const Monoid &M1,
        const OperatorMonoid OM0, const C c = [](OperatorMonoid a, int b){return a;})
        : f(f), g(g), h(h), M1(M1), OM0(OM0), c(c)
    {
        sz = 1;
        while(sz < n)   sz <<= 1;
        data.assign(sz << 1, M1);
        lazy.assign(sz << 1, OM0);
    }

    void set(int k, const Monoid &x){
        data[k + sz] = x;
    }

    void build(){
        for(int k = sz - 1; k > 0; --k){
            data[k] = f(data[k << 1], data[k << 1 | 1]);
        }
    }

    void propagate(int k, int len){
        if(lazy[k] != OM0){
            if(k < sz){
                lazy[k << 1] = h(lazy[k << 1], lazy[k]);
                lazy[k << 1 | 1] = h(lazy[k << 1 | 1], lazy[k]);
            }
            data[k] = g(data[k], c(lazy[k], len));
            lazy[k] = OM0;
        }
    }

    Monoid update(int a, int b, const OperatorMonoid &x, int k = 1, int l = 0, int r = -1){
        if(r == -1)     r = sz;
        propagate(k, r - l);
        if(r <= a || b <= l)    return data[k];
        else if(a <= l && r <= b){
            lazy[k] = h(lazy[k], x);
            propagate(k, r - l);
            return data[k];
        }
        else{
            return data[k] = f(update(a, b, x, k << 1, l, (l + r) >> 1),
                                update(a, b, x, k << 1 | 1, (l + r) >> 1, r));
        }
    }

    Monoid query(int a, int b, int k = 1, int l = 0, int r = -1){
        if(r == -1)     r = sz;
        propagate(k, r - l);
        if(r <= a || b <= l)    return M1;
        else if(a <= l && r <= b)   return data[k];
        else{
            return f(query(a, b, k << 1, l, (l + r) >> 1),
                        query(a, b, k << 1 | 1, (l + r) >> 1, r));
        }
    }

    Monoid operator[](const int &k){
        return query(k, k + 1);
    }
};

struct Data {
    int zero, one;
    ll inversion;
    Data(int zero = 0, int one = 0, ll inversion = 0)
        : zero(zero), one(one), inversion(inversion) {}
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, Q;
    cin >> N >> Q;
    auto f = [](Data l, Data r){
        return Data(l.zero + r.zero, l.one + r.one, l.inversion + r.inversion + ll(l.one) * r.zero);
    };
    auto g = [](Data d, int x){
        return Data(d.one, d.zero, ll(d.one) * d.zero - d.inversion);
    };
    auto h = [](int x, int y) { return x ^ y; };
    LazySegmentTree<Data, int> seg(N, f, g, h, Data(0, 0, 0), 0);
    for(int i = 0; i < N; ++i){
        int A;
        cin >> A;
        if(A)   seg.set(i, Data(0, 1, 0));
        else    seg.set(i, Data(1, 0, 0));
    }
    seg.build();
    for(int i = 0; i < Q; ++i){
        int T, L, R;
        cin >> T >> L >> R;
        --L;
        if(T == 1)  seg.update(L, R, 1);
        else    cout << seg.query(L, R).inversion << '\n';
    }
}