AT_ttpc2024_1_l Long Sequence Inversion 2
Description
In this problem, when we refer to a "permutation of length $ K $ ", we mean a permutation of $ (0, 1, \dots, K - 1) $ . Also, we denote the $ k $ -th element ( $ 0 $ -based) of a sequence $ X $ as $ X[k] $ .
You are given a permutation $ P $ of length $ L $ , and $ L $ permutations of length $ B $ , denoted as $ V_{0}, V_{1}, \dots, V_{L - 1} $ .
We define a sequence $ A $ of length $ B^L $ as follows:
> For each $ 0
Input Format
Input is given from standard input in the following format:
> $ L $ $ B $ $ P[0] $ $ P[1] $ $ \cdots $ $ P[L - 1] $ $ V_{0}[0] $ $ V_{0}[1] $ $ \cdots $ $ V_{0}[B - 1] $ $ \vdots $ $ V_{L - 1}[0] $ $ V_{L - 1}[1] $ $ \cdots $ $ V_{L - 1}[B - 1] $
Output Format
Print the answer.
Explanation/Hint
### Sample Explanation 1
For example, when $ n = 5 $ , since $ N = (1, 0, 1) $ , we have $ A[5] = V_{0}[1] \cdot 2^{P[0]} + V_{1}[0] \cdot 2^{P[1]} + V_{2}[1] \cdot 2^{P[2]}=3 $ .
By calculating similarly, we get $ A = (5, 1, 4, 0, 7, 3, 6, 2) $ . The inversion count of $ A $ is $ 14 $ , so output $ 14 $ .
### Sample Explanation 2
$ A = (9, 1, 13, 5, 10, 2, 14, 6, 11, 3, 15, 7, 8, 0, 12, 4) $ . The inversion count of $ A $ is $ 60 $ , so output $ 60 $ .
### Sample Explanation 3
Output the answer modulo $ 998244353 $ .
### Constraints
- All input values are integers
- $ 1 \leq L $
- $ 2 \leq B $
- $ L \times (B + 1) \leq 5 \times 10^{5} $
- $ P $ is a permutation of length $ L $
- For each $ 0 \leq i < L $ , $ V_{i} $ is a permutation of length $ B $