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
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

template<ll mod>
struct Mod_Int{
    ll x;

    Mod_Int() = default;

    Mod_Int(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    Mod_Int &operator += (const Mod_Int &p){
        x = (x + p.x) % mod;
        return *this;
    }

    Mod_Int &operator -= (const Mod_Int &p){
        x = (x + mod - p.x) % mod;
        return *this;
    }

    Mod_Int &operator *= (const Mod_Int &p){
        x = (x * p.x) % mod;
        return *this;
    }

    Mod_Int &operator /= (const Mod_Int &p){
        *this *= p.inverse();
        return *this;
    }

    Mod_Int &operator ++ () {return *this += Mod_Int(1);}

    Mod_Int operator ++ (int){
        Mod_Int tmp = *this;
        ++*this;
        return tmp;
    }

    Mod_Int &operator -- () {return *this -= Mod_Int(1);}

    Mod_Int operator -- (int){
        Mod_Int tmp = *this;
        --*this;
        return tmp;
    }

    Mod_Int operator - () const {return Mod_Int(-x);}

    Mod_Int operator + (const Mod_Int &p) const {return Mod_Int(*this) += p;}

    Mod_Int operator - (const Mod_Int &p) const {return Mod_Int(*this) -= p;}

    Mod_Int operator * (const Mod_Int &p) const {return Mod_Int(*this) *= p;}

    Mod_Int operator / (const Mod_Int &p) const {return Mod_Int(*this) /= p;}

    bool operator == (const Mod_Int &p) const {return x == p.x;}

    bool operator != (const Mod_Int &p) const {return x != p.x;}

    Mod_Int inverse() const {
        assert(*this != Mod_Int(0));
        return pow(mod-2);
    }

    Mod_Int pow(ll k) const{
        Mod_Int now = *this, ret = 1;
        while(k){
            if(k&1) ret *= now;
            now *= now, k >>= 1;
        }
        return ret;
    }

    friend ostream &operator << (ostream &os, const Mod_Int &p){
        return os << p.x;
    }

    friend istream &operator >> (istream &is, Mod_Int &p){
        ll a;
        is >> a;
        p = Mod_Int<mod>(a);
        return is;
    }
};

using mint = Mod_Int<MOD>;

template<typename Monoid, typename Operator_Monoid>
struct Lazy_Segment_Tree{
    vector<Monoid> seg;
    vector<Operator_Monoid> lazy;
    const Monoid e1;
    const Operator_Monoid e2;
    const int n;

    Monoid f(const Monoid &a, const Monoid &b) const {return a+b;}

    Monoid g(const Monoid &a, const Operator_Monoid &b) const{
        return a*b.x + b.y;
    }

    Operator_Monoid h(const Operator_Monoid &a, const Operator_Monoid &b) const{
        return {a.x*b.x, a.y*b.x + b.y};
    }
    
    Lazy_Segment_Tree(int N, const Monoid &e1, const Operator_Monoid &e2)
        : e1(e1), e2(e2), n(1<<(32-__builtin_clz(N-1))){
        seg.assign(2*n, e1), lazy.assign(2*n, e2);
    }

    void set(int i, const Monoid &x) {seg[n+i] = x;}

    void build(){
        rep3(i, n-1, 1) seg[i] = f(seg[2*i], seg[2*i+1]);
    }

    void init(int N, const Monoid &x){
        rep(i, N) set(i, x);
        build();
    }
    
    void eval(int i, int l, int r){
        if(lazy[i] != e2){
            //seg[i] = g(seg[i], lazy[i]*(r-l));
            Monoid memo = lazy[i].y;
            lazy[i].y *= r-l;
            seg[i] = g(seg[i], lazy[i]);
            lazy[i].y = memo;
            if(r-l > 1){
                lazy[2*i] = h(lazy[2*i] ,lazy[i]);
                lazy[2*i+1] = h(lazy[2*i+1], lazy[i]);
            }
            lazy[i] = e2;
        }
    }
    
    void add(int a, int b, const Operator_Monoid &x, int i, int l, int r){
        eval(i, l, r);
        if(a >= r || b <= l) return;
        if(a <= l && r <= b){
            lazy[i] = h(lazy[i], x);
            eval(i, l, r);
        }
        else{
            add(a, b, x, 2*i, l, (l+r)/2);
            add(a, b, x, 2*i+1, (l+r)/2, r);
            seg[i] = f(seg[2*i], seg[2*i+1]);
        }
    }

    void add(int a, int b, const Operator_Monoid &x) {add(a, b, x, 1, 0, n);}
    
    Monoid query(int a, int b, int i, int l, int r){
        eval(i, l, r);
        if(a >= r || b <= l) return e1;
        if(a <= l && r <= b) return seg[i];
        Monoid vl = query(a, b, 2*i, l, (l+r)/2);
        Monoid vr = query(a, b, 2*i+1, (l+r)/2, r);
        return f(vl, vr);
    }

    Monoid query(int a, int b) {return query(a, b, 1, 0, n);}
    
    void update(int i, int l, int r){
        seg[i] = g(seg[i], lazy[i]);
        if(r-l > 1){
            lazy[2*i] = h(lazy[2*i], lazy[i]);
            lazy[2*i+1] = h(lazy[2*i+1], lazy[i]);
            update(2*i, l, (l+r)/2);
            update(2*i+1, (l+r)/2, r);
        }
        lazy[i] = e2;
    }

    void update() {update(1, 0, n);}
    
    Monoid operator [] (int i) const {return seg[n+i];}
    
    void clear(){
        fill(all(seg), e1), fill(all(lazy), e2);
    }
};

struct Data{
    mint x, y;
    Data(mint x, mint y) : x(x), y(y) {}

    bool operator == (const Data &a) const {return x == a.x && y == a.y;}

    bool operator != (const Data &a) const {return !(*this == a);}
};

int main(){
    int N, Q;
    cin >> N >> Q;
    Lazy_Segment_Tree<mint, Data> seg(N, 0, {1, 0});
    rep(i, N){
        mint a; cin >> a;
        seg.set(i, a);
    }
    seg.build();
    while(Q--){
        int q, l, r; cin >> q >> l >> r;
        if(q == 0){
            mint x, y; cin >> x >> y;
            seg.add(l, r, {x, y});
        }
        else cout << seg.query(l, r) << endl;
    }
}