#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

const int MOD = 998244353;

struct Node {
    int l, r;
    long long ans, b, c;
    bool lazy = false;

    void leaf(int val) {
        ans = val;
    }

    void pull(Node &a, Node &b) {
        ans = a.ans + b.ans;
        if (ans >= MOD)
            ans -= MOD;
    }

    void push(int _b, int _c) {
        if (lazy) {
            b = b * _b % MOD;
            c = (_b * c % MOD + _c) % MOD;
        } else {
            lazy = true;
            b = _b;
            c = _c;
        }
    }

    void apply() {
        ans = (b * ans % MOD + c * (r - l + 1) % MOD) % MOD;
        lazy = false;
    }
};

struct SegmentTree {
    int n;
    vector<int> a;
    vector<Node> st;

    SegmentTree(const vector<int> &_a) : n(_a.size()), a(_a), st(4*n) {
        build(1, 0, n-1);
    }

    void build(int p, int l, int r) {
        st[p].l = l;
        st[p].r = r;
        if (l == r) {
            st[p].leaf(a[l]);
            return;
        }

        int m = (l + r) / 2;
        build(2*p, l, m);
        build(2*p+1, m+1, r);
        st[p].pull(st[2*p], st[2*p+1]);
    }

    void push(int p) {
        if (st[p].lazy) {
            if (st[p].l != st[p].r) {
                st[2*p].push(st[p].b, st[p].c);
                st[2*p+1].push(st[p].b, st[p].c);
            }
            st[p].apply();
        }
    }

    Node query(int p, int i, int j) {
        push(p);

        if (st[p].l == i && st[p].r == j)
            return st[p];

        int m = (st[p].l + st[p].r) / 2;
        if (j <= m)
            return query(2*p, i, j);
        else if (i > m)
            return query(2*p+1, i, j);
        Node ret, ls = query(2*p, i, m), rs = query(2*p+1, m+1, j);
        ret.pull(ls, rs);
        return ret;
    }

    int query(int i, int j) {
        return query(1, i, j).ans;
    }

    void update(int p, int i, int j, int b, int c) {
        if (st[p].l == i && st[p].r == j) {
            st[p].push(b, c);
            push(p);
            return;
        }

        push(p);

        int m = (st[p].l + st[p].r) / 2;
        if (j <= m) {
            update(2*p, i, j, b, c);
            push(2*p+1);
        } else if (i > m) {
            push(2*p);
            update(2*p+1, i, j, b, c);
        } else {
            update(2*p, i, m, b, c);
            update(2*p+1, m+1, j, b, c);
        }
        st[p].pull(st[2*p], st[2*p+1]);
    }

    void update(int i, int j, int b, int c) {
        update(1, i, j, b, c);
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i=0; i<n; i++)
        cin >> a[i];

    SegmentTree st(a);
    for (int i=0; i<q; i++) {
        int type, l, r;
        cin >> type >> l >> r;
        r--;
        if (type == 0) {
            int b, c;
            cin >> b >> c;
            st.update(l, r, b, c);
        } else {
            cout << st.query(l, r) << "\n";
        }
    }

    return 0;
}

### Prompt

Develop a solution in cpp to the problem described below:

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

const int MOD = 998244353;

struct Node {
    int l, r;
    long long ans, b, c;
    bool lazy = false;

    void leaf(int val) {
        ans = val;
    }

    void pull(Node &a, Node &b) {
        ans = a.ans + b.ans;
        if (ans >= MOD)
            ans -= MOD;
    }

    void push(int _b, int _c) {
        if (lazy) {
            b = b * _b % MOD;
            c = (_b * c % MOD + _c) % MOD;
        } else {
            lazy = true;
            b = _b;
            c = _c;
        }
    }

    void apply() {
        ans = (b * ans % MOD + c * (r - l + 1) % MOD) % MOD;
        lazy = false;
    }
};

struct SegmentTree {
    int n;
    vector<int> a;
    vector<Node> st;

    SegmentTree(const vector<int> &_a) : n(_a.size()), a(_a), st(4*n) {
        build(1, 0, n-1);
    }

    void build(int p, int l, int r) {
        st[p].l = l;
        st[p].r = r;
        if (l == r) {
            st[p].leaf(a[l]);
            return;
        }

        int m = (l + r) / 2;
        build(2*p, l, m);
        build(2*p+1, m+1, r);
        st[p].pull(st[2*p], st[2*p+1]);
    }

    void push(int p) {
        if (st[p].lazy) {
            if (st[p].l != st[p].r) {
                st[2*p].push(st[p].b, st[p].c);
                st[2*p+1].push(st[p].b, st[p].c);
            }
            st[p].apply();
        }
    }

    Node query(int p, int i, int j) {
        push(p);

        if (st[p].l == i && st[p].r == j)
            return st[p];

        int m = (st[p].l + st[p].r) / 2;
        if (j <= m)
            return query(2*p, i, j);
        else if (i > m)
            return query(2*p+1, i, j);
        Node ret, ls = query(2*p, i, m), rs = query(2*p+1, m+1, j);
        ret.pull(ls, rs);
        return ret;
    }

    int query(int i, int j) {
        return query(1, i, j).ans;
    }

    void update(int p, int i, int j, int b, int c) {
        if (st[p].l == i && st[p].r == j) {
            st[p].push(b, c);
            push(p);
            return;
        }

        push(p);

        int m = (st[p].l + st[p].r) / 2;
        if (j <= m) {
            update(2*p, i, j, b, c);
            push(2*p+1);
        } else if (i > m) {
            push(2*p);
            update(2*p+1, i, j, b, c);
        } else {
            update(2*p, i, m, b, c);
            update(2*p+1, m+1, j, b, c);
        }
        st[p].pull(st[2*p], st[2*p+1]);
    }

    void update(int i, int j, int b, int c) {
        update(1, i, j, b, c);
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i=0; i<n; i++)
        cin >> a[i];

    SegmentTree st(a);
    for (int i=0; i<q; i++) {
        int type, l, r;
        cin >> type >> l >> r;
        r--;
        if (type == 0) {
            int b, c;
            cin >> b >> c;
            st.update(l, r, b, c);
        } else {
            cout << st.query(l, r) << "\n";
        }
    }

    return 0;
}

```