atcoder#ARC158F. [ARC158F] Random Radix Sort

[ARC158F] Random Radix Sort

Score : 900900 points

Problem Statement

For non-negative integers xx and kk, the kk-th lowest digit of xx is the remainder when x10k\bigl\lfloor \frac{x}{10^k}\bigr\rfloor is divided by 1010. For instance, the 00-th, 11-st, 22-nd, and 33-rd lowest digits of 123123 are 33, 22, 11, and 00, respectively.

You are given positive integers NN, MM, KK, and sequences of non-negative integers A=(A1,,AN)A = (A_1, \ldots, A_N) and B=(B1,,BN)B = (B_1, \ldots, B_N).

Consider rearranging AA by the following process.

  • Do the following MM times.- Choose an integer kk such that 0kK10\leq k \leq K - 1.
    • Then, perform a stable sort on AA by kk-th lowest digit. That is, let A(d)A^{(d)} be the subsequence of AA composed of all elements of AA whose kk-th lowest digits are dd, and replace AA with the concatenation of A(0),A(1),,A(9)A^{(0)}, A^{(1)}, \ldots, A^{(9)} in this order.
  • Choose an integer kk such that 0kK10\leq k \leq K - 1.
  • Then, perform a stable sort on AA by kk-th lowest digit. That is, let A(d)A^{(d)} be the subsequence of AA composed of all elements of AA whose kk-th lowest digits are dd, and replace AA with the concatenation of A(0),A(1),,A(9)A^{(0)}, A^{(1)}, \ldots, A^{(9)} in this order.

There are KMK^M ways to execute this process. How many of them end up making AA equal BB? Find this count modulo 998244353998244353.

Constraints

  • 1N2×1051\leq N\leq 2\times 10^5
  • 1M1091\leq M\leq 10^9
  • 1K181\leq K\leq 18
  • 0Ai<10K0\leq A_i < 10^K
  • 0Bi<10K0\leq B_i < 10^K
  • AA and BB are equal as multisets. That is, every integer xx occurs the same number of times in AA and BB.

Input

The input is given from Standard Input in the following format:

NN MM KK

A1A_1 \ldots ANA_N

B1B_1 \ldots BNB_N

Output

Print the number, modulo 998244353998244353, of ways to execute the process that end up making AA equal BB.

3 2 3
74 42 54
42 54 74
5

Let k1k_1 and k2k_2 be the kk chosen in the first and second iterations, respectively. For instance, if k1=0k_1 = 0 and k2=1k_2 = 1, then AA changes as follows.

  • A stable sort by k1k_1-th (00-th) lowest digit makes A=(42,74,54)A = (42,74,54).
  • A stable sort by k2k_2-th (11-st) lowest digit makes A=(42,54,74)A = (42,54,74).

Here are all the ways to execute the process and the resulting AA.

  • (k1,k2)=(0,0)(k_1, k_2) = (0,0): A=(42,74,54)A = (42,74,54).
  • (k1,k2)=(0,1)(k_1, k_2) = (0,1): A=(42,54,74)A = (42,54,74).
  • (k1,k2)=(0,2)(k_1, k_2) = (0,2): A=(42,74,54)A = (42,74,54).
  • (k1,k2)=(1,0)(k_1, k_2) = (1,0): A=(42,54,74)A = (42,54,74).
  • (k1,k2)=(1,1)(k_1, k_2) = (1,1): A=(42,54,74)A = (42,54,74).
  • (k1,k2)=(1,2)(k_1, k_2) = (1,2): A=(42,54,74)A = (42,54,74).
  • (k1,k2)=(2,0)(k_1, k_2) = (2,0): A=(42,74,54)A = (42,74,54).
  • (k1,k2)=(2,1)(k_1, k_2) = (2,1): A=(42,54,74)A = (42,54,74).
  • (k1,k2)=(2,2)(k_1, k_2) = (2,2): A=(74,42,54)A = (74,42,54).
2 1 1
2 3
3 2
0

There is no way to satisfy the condition.

5 100 4
0 12 34 56 78
0 12 34 56 78
982924732

All 41004^{100} ways satisfy the condition.