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:
/*  -*- coding: utf-8 -*-
 *
 * l.cc: L - Lazy Segment Tree
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 200000;
const int MAX_E2 = 1 << 19; // = 524288

/* typedef */

typedef long long ll;

struct Elm {
  int z, o;
  ll c0, c1;
  Elm() {}
  Elm(int _z, int _o): z(_z), o(_o), c0(0), c1(0) {}
  Elm(int _z, int _o, ll _c0, ll _c1): z(_z), o(_o), c0(_c0), c1(_c1) {}

  Elm operator+(const Elm &e) const {
    return Elm(z + e.z, o + e.o,
	       c0 + e.c0 + (ll)o * e.z, c1 + e.c1 + (ll)z * e.o);
  }

  Elm &rev() {
    swap(z, o); swap(c0, c1);
    return *this;
  }
};

template <typename T, const int MAX_E2>
struct SegTreeDelay {
  int e2;
  T nodes[MAX_E2], zero;
  bool dls[MAX_E2];
  SegTreeDelay() {}

  void init(int n, T _zero) {
    zero = _zero;
    for (e2 = 1; e2 < n; e2 <<= 1);
    fill(nodes, nodes + MAX_E2, zero);
    //fill(dls, dls + MAX_E2, false);
  }

  T &get(int i) { return nodes[e2 - 1 + i]; }
  void seti(int i, T v) { get(i) = v; }

  void setall() {
    for (int j = e2 - 2; j >= 0; j--)
      nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];
  }

  void __update(int k) {
    if (dls[k]) {
      int k0 = k * 2 + 1, k1 = k0 + 1;
      nodes[k0].rev();
      nodes[k1].rev();
      dls[k0] ^= true;
      dls[k1] ^= true;
      dls[k] = false;
    }
  }

  void rev_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return;
    if (r0 <= i0 && i1 <= r1) {
      nodes[k].rev();
      dls[k] ^= true;
      return;
    }

    __update(k);

    int im = (i0 + i1) / 2;
    int k0 = k * 2 + 1, k1 = k0 + 1;
    rev_range(r0, r1, k0, i0, im);
    rev_range(r0, r1, k1, im, i1);
    nodes[k] = nodes[k0] + nodes[k1];
  }
  void rev_range(int r0, int r1) { rev_range(r0, r1, 0, 0, e2); }

  T sum_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return zero;
    if (r0 <= i0 && i1 <= r1) return nodes[k];

    __update(k);

    int im = (i0 + i1) / 2;
    T v0 = sum_range(r0, r1, k * 2 + 1, i0, im);
    T v1 = sum_range(r0, r1, k * 2 + 2, im, i1);
    return v0 + v1;
  }
  T sum_range(int r0, int r1) { return sum_range(r0, r1, 0, 0, e2); }
};

/* global variables */

SegTreeDelay<Elm,MAX_E2> st;

/* subroutines */

/* main */

int main() {
  int n, q;
  scanf("%d%d", &n, &q);

  st.init(n, Elm(0, 0));

  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    st.seti(i, Elm(1 - ai, ai));
  }
  st.setall();

  while (q--) {
    int op, l, r;
    scanf("%d%d%d", &op, &l, &r);
    l--;

    if (op == 1) {
      st.rev_range(l, r);
    }
    else {
      Elm e = st.sum_range(l, r);
      printf("%lld\n", e.c0);
    }
  }
  return 0;
}