#P14808. [CCPC 2024 哈尔滨站] 子序列计数

[CCPC 2024 哈尔滨站] 子序列计数

Description

Given a sequence {t}\{t\} of length mm and a sequence {s}\{s\} of length LL, where {s}\{s\} is composed of nn consecutive segments from left to right. The ii-th segment contains lil_i identical elements, each with a value of viv_i.

The sequence {s}\{s'\} is formed by shuffling the sequence {s}\{s\} according to a certain rule. Specifically, the sequence {s}\{s'\} satisfies sikmodL=sis'_{i \cdot k \bmod L} = s_i (indices start from 00). Here, kk is a given positive integer constant, and it is guaranteed that gcd(k,L)=1\gcd(k, L) = 1.

Find the number of times {t}\{t\} appears as a subsequence in {s}\{s'\}. Formally, if there is a strictly increasing sequence of indices 0i1<i2<<im<L0 \le i_1 < i_2 < \dots < i_m < L such that for each j=1,2,,mj = 1, 2, \dots, m, tj=sijt_j = s'_{i_j}, then {t}\{t\} is considered a subsequence of {s}\{s'\} at these indices. You need to determine how many different index groups satisfy this condition. Since the answer may be large, output the result modulo 998244353998244353.

Input Format

The first line contains four integers n,m,k,Ln, m, k, L (1n2×1031 \le n \le 2 \times 10^3, 1m101 \le m \le 10, 1k<L1091 \le k < L \le 10^9, gcd(k,L)=1\gcd(k, L) = 1).

The second line contains mm integers representing the sequence {t}\{t\} (1ti1031 \le t_i \le 10^3).

The next nn lines describe the sequence {s}\{s\}, each containing two integers li,vil_i, v_i (1li1091 \le l_i \le 10^9, 1vi1031 \le v_i \le 10^3). It is guaranteed that i=1nli=L\sum_{i=1}^n l_i = L.

Output Format

Output a single integer, representing the result modulo 998244353998244353.

4 2 17 27
3 1
10 3
6 1
10 3
1 1
76
5 3 1789 15150
555 718 726
72 555
1029 718
5807 726
1002 718
7240 555
390415327