output_description: For each query of the latter type, print the answer.
  
  * * *
input_description: 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}
attempt: class Lazy_Evaluation_Tree:
      def __init__(self, L, calc, unit, op, comp, id):
          """calcを演算,opを作用とするリストLのSegment Treeを作成
  
          calc:演算
          unit:モノイドcalcの単位元 (xe=ex=xを満たすe)
          op:作用素
          comp:作用素の合成
          id:恒等写像
  
          [条件] M:Monoid,F={f:F x M→ M:作用素}に対して,以下が成立する.
          Fは恒等写像 id を含む.つまり,任意の x in M に対して id(x)=x
          Fは写像の合成に閉じている.つまり,任意の f,g in F に対して, comp(f,g) in F
          任意の f in F, x,y in M に対して,f(xy)=f(x)f(y)である.
          """
  
          self.calc = calc
          self.unit = unit
          self.op = op
          self.comp = comp
          self.id = id
  
          N = len(L)
  
          d = max(1, (N - 1).bit_length())
          k = 2**d
  
          X = [unit] * (k - 1) + L + [unit] * (k - len(L))
  
          self.num = k
          self.depth = d
  
          for i in range(k - 2, -1, -1):
              X[i] = calc(X[2 * i + 1], X[2 * i + 2])
  
          self.data = X
          self.lazy = [self.id] * (2 * k - 1)
  
      def eval(self, k):
          if self.lazy[k] == self.id:  # 単位元だったら終了
              return
  
          if k < self.num - 1:  # 葉でなければ子に伝搬
              self.lazy[2 * k + 1] = self.lazy[k]
              self.lazy[2 * k + 2] = self.lazy[k]
  
          # 自身を更新(作用)
          self.data[k] = self.op(self.lazy[k], self.data[k])
          self.lazy[k] = self.id
  
      def get(self, k, index=0):
          return self.product(k, k, index)
  
      def operate(self, From, To, alpha, index=0, left_closed=True, right_closed=True):
          A = From - index + (not left_closed)
          B = To - index - (not right_closed)
  
          return self.__operate_second(A, B + 1, alpha, 0, 0, self.num)
  
      def __operate_second(self, a, b, alpha, k, l, r):
          self.eval(k)
          if (a <= l) and (r <= b):  # 完全に内側のとき
              self.lazy[k] = self.comp(alpha, self.lazy[k])
              self.eval(k)
          elif (a < r) and (l < b):  # 一部がかぶるとき
              self.__operate_second(a, b, alpha, 2 * k + 1, l, (l + r) // 2)  # 左の子
              self.__operate_second(a, b, alpha, 2 * k + 2, (l + r) // 2, r)  # 右の子
              self.data[k] = self.calc(self.data[2 * k + 1], self.data[2 * k + 2])
  
      def update(self, k, x):
          pass
  
      def product(self, From, To, index=0, left_closed=True, right_closed=True):
          A = From - index + (not left_closed)
          B = To - index - (not right_closed)
  
          return self.__product_second(A, B + 1, 0, 0, self.num)
  
      def __product_second(self, a, b, k, l, r):
          self.eval(k)
          if r <= a or b <= l:
              return self.unit
          elif a <= l and r <= b:
              return self.data[k]
          else:
              alpha = self.__product_second(a, b, 2 * k + 1, l, (l + r) // 2)
              beta = self.__product_second(a, b, 2 * k + 2, (l + r) // 2, r)
              return self.calc(alpha, beta)
  
  
  # ================================================
  N, Q = map(int, input().split())
  Mod = 998244353
  A = list(map(int, input().split()))
  
  op = lambda t, x: (t[0] * x + t[1]) % Mod
  comp = lambda u, t: ((u[0] * t[0]) % Mod, (u[1] + u[0] * t[1]) % Mod)
  
  L = Lazy_Evaluation_Tree(A, lambda x, y: (x + y) % Mod, 0, op, comp, (1, 0))
  
  X = []
  for _ in range(Q):
      R = tuple(map(int, input().split()))
      if R[0] == 0:
          _, l, r, b, c = R
          L.operate(l, r - 1, (b, c))
      else:
          _, l, r = R
          X.append(L.product(l, r - 1))
  
  print("\n".join(map(str, X)))
  
problem_description: Statement
  
  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.
samples: [{"input": "5 7\n    1 2 3 4 5\n    1 0 5\n    0 2 4 100 101\n    1 0 3\n    0 1 3 102 103\n    1 2 5\n    0 2 5 104 105\n    1 0 5", "output": "15\n    404\n    41511\n    4317767"}]