Problem: You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types.

* `0 l r b c`: For each i = l, l+1, \dots, {r - 1}, set a_i \gets b \times a_i + c.
* `1 l r`: Print \sum_{i = l}^{r - 1} a_i \bmod 998244353.

Constraints

* 1 \leq N, Q \leq 500000
* 0 \leq a_i, c < 998244353
* 1 \leq b < 998244353
* 0 \leq l < r \leq N
* All values in Input are integer.

Input

Input is given from Standard Input in the following format:


N Q
a_0 a_1 ... a_{N - 1}
\textrm{Query}_0
\textrm{Query}_1
:
\textrm{Query}_{Q - 1}


Output

For each query of the latter type, print the answer.

Example

Input

5 7
1 2 3 4 5
1 0 5
0 2 4 100 101
1 0 3
0 1 3 102 103
1 2 5
0 2 5 104 105
1 0 5


Output

15
404
41511
4317767

Solution (in CPP):

Solution:
/*  -*- coding: utf-8 -*-
 *
 * k.cc: K - Range Affine Range Sum
 */

#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 = 500000;
const int MAX_E2 = 1 << 20; // = 1048576
const int MOD = 998244353;

/* typedef */

typedef long long ll;

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

  void init(int n) {
    for (e2 = 1; e2 < n; e2 <<= 1);
    //fill(nodes, nodes + MAX_E2, 0);
    fill(bs, bs + MAX_E2, 1);
    //fill(cs, cs + MAX_E2, 0);
    //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]) % MOD;
  }

  // b1(b0*a+c0)+c1 = (b1*b0)*a+(b1*c0+c1)
  void __update(int k, int l) {
    if (dls[k]) {
      int hl = l / 2;
      int k0 = k * 2 + 1, k1 = k0 + 1;
      nodes[k0] = ((ll)bs[k] * nodes[k0] % MOD + (ll)cs[k] * hl % MOD) % MOD;
      nodes[k1] = ((ll)bs[k] * nodes[k1] % MOD + (ll)cs[k] * hl % MOD) % MOD;
      cs[k0] = ((ll)cs[k0] * bs[k] % MOD + cs[k]) % MOD;
      cs[k1] = ((ll)cs[k1] * bs[k] % MOD + cs[k]) % MOD;
      bs[k0] = (ll)bs[k0] * bs[k] % MOD;
      bs[k1] = (ll)bs[k1] * bs[k] % MOD;
      bs[k] = 1, cs[k] = 0;
      dls[k0] = dls[k1] = true;
      dls[k] = false;
    }
  }

  void set_range(int r0, int r1, int b, int c, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return;
    if (r0 <= i0 && i1 <= r1) {
      nodes[k] = ((ll)b * nodes[k] % MOD + (ll)c * (i1 - i0) % MOD) % MOD;
      cs[k] = ((ll)cs[k] * b % MOD + c) % MOD;
      bs[k] = (ll)bs[k] * b % MOD;
      dls[k] = true;
      return;
    }

    __update(k, i1 - i0);

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

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

    __update(k, i1 - i0);

    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) % MOD;
  }
  T sum_range(int r0, int r1) { return sum_range(r0, r1, 0, 0, e2); }
};

/* global variables */

SegTreeDelay<int,MAX_E2> st;

/* subroutines */

/* main */

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

  st.init(n);

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

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

    if (op == 0) {
      int b, c;
      scanf("%d%d", &b, &c);
      st.set_range(l, r, b, c);

      //for (int i = 0; i < n; i++) printf(" %d", st.sum_range(i, i + 1));
      //putchar('\n');
    }
    else {
      int v = st.sum_range(l, r);
      printf("%d\n", v);
    }
  }
  return 0;
}