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;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 998244353;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template <typename T,typename E>
struct LazySegmentTree{
    typedef function<T(T,T)> F;
    typedef function<T(T,E)> G;
    typedef function<E(E,E)> H;
    typedef function<pair<ll,ll>(E,int)> P;
    int n;
    F f;
    G g;
    H h;
    P p;
    T d1;
    E d0;
    vector<T> val;
    vector<E> lazy;

    LazySegmentTree(vector<T> a, F f_, G g_, H h_, T d1_, E d0_, P p_=[](E a,int b){return a;}):
        f(f_),g(g_),h(h_),d1(d1_),d0(d0_),p(p_){

        int sz = a.size();
        n = 1;
        while (n < sz) n <<= 1;
        val.clear();
        val.resize(2 * n - 1, d1);
        lazy.clear();
        lazy.resize(2 * n - 1, d0);
        for (int i = 0; i < sz; i++) val[i + n - 1] = a[i];
        for (int i = n - 2; i >= 0; i--) val[i] = f(val[i * 2 + 1], val[i * 2 + 2]);
    }

    inline void eval(int k, int len){
        if(lazy[k] == d0) return;

        if(2*k+1 < 2*n-1){
            lazy[2*k+1] = h(lazy[2*k+1], lazy[k]);
            lazy[2*k+2] = h(lazy[2*k+2], lazy[k]);
        }
        val[k] = g(val[k], p(lazy[k], len));
        lazy[k] = d0;
    }

    void update(int a, int b, E x, int k=0, int l=0, int r=-1){
        // 0-indexed
        // [a,b)に対して操作
        if(r < 0) r = n;
        eval(k, r-l);
        if(r <=a || b <= l) return;

        if(a <= l && r <= b){
            lazy[k] = h(lazy[k], x);
            eval(k, r-l);
        }
        else{
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            val[k] = f(val[2*k+1], val[2*k+2]);
        }
    }

    T query(int a, int b, int k=0, int l=0, int r=-1){
        // 0-indexed
        // [a,b)に対してquery
        if(r < 0) r = n;
        eval(k, r-l);
        if(r <= a || b <= l) return d1;
        if(a <= l && r <= b) return val[k];
        T val_l = query(a, b , 2*k+1, l, (l+r)/2);
        T val_r = query(a, b , 2*k+2, (l+r)/2, r);
        return f(val_l, val_r);
    }

    int findL(int a, int b, const function<bool(T)>& check, int k=0, int l=0, int r=-1){
        // 0-indexed
        // [a,b)でf(val[k])がtrueとなるような最小のkを返す 無ければ-1を返す
        // a      k         b
        // xxxxxxxoooooooooo

        if(r<0) r = n;
        eval(k, r-l);
        if(!check(val[k]) || (r<=a || b<=l)) return -1;
        if(r-l == 1) return l;

        int lv = findL(a, b, check, 2*k+1, l, (l+r)/2);
        if(lv != -1) return lv;

        int rv = findL(a, b, check, 2*k+2, (l+r)/2, r);
        return rv;
    }

    int findR(int a, int b, const function<bool(T)>& check, int k=0, int l=0, int r=-1){
        // 0-indexed
        // [a,b)でf(val[k])がtrueとなるような最大のkを返す 無ければ-1を返す
        // a      k         b
        // ooooooooxxxxxxxxx

        if(r<0) r = n;
        eval(k, r-l);
        if(!check(val[k]) || (r<=a || b<=l)) return -1;
        if(r-l == 1) return l;

        int rv = findR(a, b, check, 2*k+2, (l+r)/2, r);
        if(rv != -1) return rv;

        int lv = findR(a, b, check, 2*k+1, l, (l+r)/2);
        return lv;
    }
};

ll f(ll a, ll b){return (a+b)%MOD;}
ll g(ll a, pair<ll,ll> b){
    ll x = b.first, y = b.second;
    return (x*a + y) % MOD;
}
pair<ll,ll> h(pair<ll,ll> a, pair<ll,ll> b){
    return pair<ll,ll>((a.first*b.first)%MOD, (b.first*a.second+b.second)%MOD);
}
pair<ll,ll> p(pair<ll,ll> a, int b){
    return pair<ll,ll>(a.first, (a.second*b)%MOD);
}

void Main(){
    int N,Q; cin >> N >> Q;
    VL A(N); REP(i,N) cin >> A[i];

    LazySegmentTree<ll,pair<ll,ll>> st(A,f,g,h,0,pair<ll,ll>(1,0),p);
    REP(_,Q){
        int t,l,r; cin >> t >> l >> r;
        if(t == 0){
            ll b,c; cin >> b >> c;
            st.update(l,r,pair<ll,ll>(b,c));
        }
        else{
            ll ans = st.query(l,r);
            cout << ans << en;
        }
    }
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}