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;

template<typename F, typename T, typename Func_mf, typename Func_op, typename Func_mv>
struct LazySegtree {
    int n, n_org;
    vector<T> dat;
    vector<F> laz;
    Func_mf merge_functions;
    Func_op operate;
    Func_mv merge_values;
    F fe;
    T te;

    LazySegtree(){}
    LazySegtree(int n_org,
                Func_mf merge_functions,
                Func_op operate,
                Func_mv merge_values,
                F fe, T te):
                n_org(n_org),
                merge_functions(merge_functions),
                operate(operate),
                merge_values(merge_values),
                fe(fe), te(te){
        n = 1;
        while(n < n_org) n <<= 1;
        dat.assign(2*n-1, te);
        laz.assign(2*n-1, fe);
    }

    void build(vector<T>& A){
        for(int k=0; k<int(A.size()); k++) dat[k+n-1] = A[k];
        for(int k=n-2; k>=0; k--) dat[k] = merge_values(dat[2*k+1], dat[2*k+2]);
    }

    void eval(int k, int w){
        if(laz[k] == fe) return;
        operate(dat[k], laz[k], w);
        if(k < n-1){
            merge_functions(laz[2*k+1], laz[k]);
            merge_functions(laz[2*k+2], laz[k]);
        }
        laz[k] = fe;
    }

    void update_between(int a, int b, F x){
        update(a, b+1, x, 0, 0, n);
    }

    void update(int a, int b, F x, int k, int lb, int rb){
        eval(k, rb-lb);
        if(b <= lb || rb <= a) return;
        if(a <= lb && rb <= b){
            merge_functions(laz[k], x);
            eval(k, rb-lb);
        }else{
            int mb = (lb+rb)>>1;
            update(a, b, x, 2*k+1, lb, mb);
            update(a, b, x, 2*k+2, mb, rb);
            dat[k] = merge_values(dat[2*k+1], dat[2*k+2]);
        }
    }

    T get_between(int a, int b){
        return query(a, b+1, 0, 0, n);
    }

    T query(int a, int b, int k, int lb, int rb){
        eval(k, rb-lb);
        if(rb<=a || b<=lb) return te;
        if(a<=lb && rb<=b) return dat[k];
        int mb = (lb+rb)>>1;
        T vl = query(a, b, 2*k+1, lb, mb);
        T vr = query(a, b, 2*k+2, mb, rb);
        return merge_values(vl, vr);
    }

    // [S, t] が条件checkを満たす最大のtを求める
	template<typename Func_ck>
    int lower_bound(int S, Func_ck check){
        T val = get_between(S, S);
        int k = S+n-1;
        int lb = S, rb = S+1;
        while(true){
            while(k%2){
                k = (k-1)/2;
                rb += rb-lb;
            }
			int w = rb-lb;
            eval(k, w);
            T val2 = merge_values(val, dat[k]);
            if(check(val2)){
                if(rb == n) return n_org-1;
                val = val2;
                k++;
				lb += w;
				rb += w;
            }else{
                break;
            }
        }
        while(k<n-1){
            int wh = (rb-lb)>>1;
            eval(2*k+1, wh);
            eval(2*k+2, wh);
            T val2 = merge_values(val, dat[2*k+1]);
            if(check(val2)){
                val = val2;
                k = 2*k+2;
                lb += wh;
            }else{
                k = 2*k+1;
                rb -= wh;
            }
        }
        return min(lb, n_org)-1;
    }
};

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

auto make_segtree = [](int N){
    using F = pair<int64_t, int64_t>;
    using T = int64_t;
    auto merge_functions = [](F& f, F& g){
        mul(f.first, g.first);
        mul(f.second, g.first);
        add(f.second, g.second);
    };
    auto operate = [](T& v, F& f, int w){
        mul(v, f.first);
        add(v, w * f.second);
    };
    auto merge_values = [](T& a, T& b){
        return (a+b) % MOD;
    };
    F fe = {1, 0};
    T te = 0;
    return LazySegtree<F, T, decltype(merge_functions), decltype(operate), decltype(merge_values)>
        (N, merge_functions, operate, merge_values, fe, te);
};

int main(){
    int N, Q;
    cin >> N >> Q;
    auto st = make_segtree(N);
    vector<int64_t> A(N);
    for(int i=0; i<N; i++) scanf("%lld", &A[i]);
    st.build(A);
    while(Q--){
        int t;
        scanf("%d", &t);
        if(t == 0){
            int l, r;
            int64_t b, c;
            scanf("%d %d %lld %lld", &l, &r, &b, &c);
            st.update_between(l, r-1, {b, c});
        }else{
            int l, r;
            scanf("%d %d", &l, &r);
            printf("%lld\n", st.get_between(l, r-1));
        }
    }
    return 0;
}
