#P10116. [LMXOI Round 1] Random

[LMXOI Round 1] Random

Background

LMX gives HQZ an interesting sequence. To understand LMX’s preferences, HQZ wants to solve the following problem.

Problem Description

Given an initial sequence of length nn that is all 00, we will perform the following operation qq times.

  • Choose any position tt and change the number at that position to any integer between 11 and kk.

That is, in total there are (nk)q(nk)^q different operation sequences. For each different operation sequence, there is a corresponding resulting sequence.

Next, a matching sequence BB of length mm is given. You need to compute the total number of occurrences of this matching sequence across every resulting sequence. Note that if a resulting sequence contains multiple occurrences of the matching sequence, they should be counted repeatedly.

Since the answer is too large, you only need to output the answer modulo 998244353998244353.

This problem uses a special method to generate the input data.

The generation format is: xi=(a×i+b)modk+1x_i=(a \times i+b)\bmod k +1, where xix_i denotes the required number at position ii of sequence BB.

Input Format

The first line contains four integers n,m,q,kn,m,q,k, where mm is the length of sequence BB.

The second line contains two integers a,ba,b.

Output Format

Output one integer representing the answer.

3 2 2 2
1 1
4
2 1 2 2
1 1
12
10 3 114 51419
19 2
266405589

Hint

Sample Explanation #1

For the following operation sequences, sequence BB appears:

  • [1,1],[2,2][1,1],[2,2] produces the sequence [1,2,0][1,2,0].
  • [2,2],[1,1][2,2],[1,1] produces the sequence [1,2,0][1,2,0].
  • [2,1],[3,2][2,1],[3,2] produces the sequence [0,1,2][0,1,2].
  • [3,2],[2,1][3,2],[2,1] produces the sequence [0,1,2][0,1,2].

For 100%100\% of the data, it is guaranteed that xiB,1xik\forall x_i \in B, 1\le x_i\le k, 0a,b1090 \le a,b\le 10^9, and mnm\le n.

Subtask ID n,q,kn,q,k mm Special Property Score
Subtask #1 109\le 10^9 200\le 200 q<mq< m 55
Subtask #2 4\le 4 None 1010
Subtask #3 500\le 500 200\le 200
Subtask #4 2×105\le 2\times 10^5 2020
Subtask #5 109\le 10^9
Subtask #6 3×106\le 3\times 10^6 3535

Translated by ChatGPT 5