atcoder#ARC120F. [ARC120F] Wine Thief

[ARC120F] Wine Thief

Score : 800800 points

Problem Statement

Problems F and F2 have the same Problem Statement but different Constraints and Time Limits.

There are NN bottles of wine in Takahashi's cellar, arranged in a row from left to right. The tastiness of the ii-th bottle from the left is AiA_i. Aoki will choose KK bottles from these NN and steal them. However, Takahashi is careful enough to notice the theft if the following condition is satisfied:

  • There exist DD consecutive bottles such that two or more of them are stolen. (D=2D = 2 in this problem.)

For every way of stealing bottles without getting noticed by Takahashi, find the total tastiness of the bottles stolen, and then find the sum of all those values. Since the sum can be enormous, print it modulo 998244353998244353.

Constraints

  • D=2D = 2
  • 2N3×1052 \le N \le 3 \times 10^5
  • 1KND1 \le K \le \left\lceil \frac{N}{D} \right\rceil (x\left\lceil x \right\rceil represents the smallest integer not less than xx.)
  • 1Ai<9982443531 \le A_i \lt 998244353
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK DD

A1A_1 A2A_2 A3A_3 \dots ANA_N

Output

Print the sum modulo 998244353998244353.

4 2 2
1 4 2 3
14

The possible ways to steal bottles and the total tastiness for each of them are as follows:

  • Steal the 11-st and 33-rd bottles from the left, for the total tastiness of 1+2=31 + 2 = 3.
  • Steal the 11-st and 44-th bottles from the left, for the total tastiness of 1+3=41 + 3 = 4.
  • Steal the 22-nd and 44-th bottles from the left, for the total tastiness of 4+3=74 + 3 = 7.

Thus, the answer is 3+4+7=143 + 4 + 7 = 14.

5 3 2
4 7 5 3 8
17

There is no choice but to steal the 11-st, 33-rd, and 55-th bottles.

12 4 2
107367523 266126484 149762920 57456082 857431610 400422663 768881284 494753774 152155823 740238343 871191740 450057094
136993014