#P7342. 『MdOI R4』Destiny

『MdOI R4』Destiny

Description

Note that in this problem, indices start from 00.

For a sequence {ai}\{a_i\} of length nn, its weight v(a)v(a) is defined as:

  • When n=1n=1, v(a)=a0v(a)=a_0.
  • When n>1n>1, it is the sum of the weights of all its subsegments, that is, $v(a_0,a_1,\ldots,a_{n-1})=\sum\limits_{i=0}^{n-2}\sum\limits_{j=0}^{n-i-1}v(a_j,a_{j+1},\ldots,a_{j+i})$.

Given a sequence, compute its weight, and output the answer modulo 998244353998244353.

The sequence is generated as follows: input a sequence b0,b1,,bk1b_0,b_1,\cdots,b_{k-1}, then ai=bimodka_i=b_{i\bmod k}.

Input Format

The first line contains n,kn,k, representing the length of sequence aa and the length of sequence bb.

The second line contains b0,b1,,bk1b_0,b_1,\cdots,b_{k-1}, with the meaning described above.

Output Format

Output one integer per line, representing the weight of sequence aa modulo 998244353998244353.

4 3
3 4 6

104

10 10
2 5 3 8 4 5 2 19 3 6

219856

Hint

[Sample Explanation #1]

Generate the sequence a=[3,4,6,3]a=[3,4,6,3], then:

  • v(3,4)=v(3)+v(4)=7v(3,4)=v(3)+v(4)=7
  • v(4,6)=v(4)+v(6)=10v(4,6)=v(4)+v(6)=10
  • v(6,3)=v(6)+v(3)=9v(6,3)=v(6)+v(3)=9
  • v(3,4,6)=v(3)+v(4)+v(6)+v(3,4)+v(4,6)=30v(3,4,6)=v(3)+v(4)+v(6)+v(3,4)+v(4,6)=30
  • v(4,6,3)=v(4)+v(6)+v(3)+v(4,6)+v(6,3)=32v(4,6,3)=v(4)+v(6)+v(3)+v(4,6)+v(6,3)=32
  • $v(3,4,6,3)=v(3)+v(4)+v(6)+v(3)+v(3,4)+v(4,6)+v(6,3)+v(3,4,6)+v(4,6,3)=104$

[Constraints]

This problem does not use bundled tests.

There are 2525 test points in total, and each test point is worth 44 points.

Test Point ID nn\le kk
131\sim 3 50005000 No special restrictions
4104\sim 10 10510^5
111511\sim 15 No special restrictions =60928=60928
162516\sim 25 No special restrictions

For 100%100\% of the testdata: 1n1091\le n\le 10^91k1051 \le k \le 10^50ai9982443520\le a_i\le 998244352

Thanks to JohnVictor\rm\textcolor{black}{J}\textcolor{red}{ohnVictor} for contributing to this problem.

Translated by ChatGPT 5