#P2435. 染色

染色

Description

There is an nn-row, mm-column grid graph. You need to color each point with one of kk colors so that no two adjacent points have the same color. Given the colorings of the first row and the last row, find the total number of valid colorings.

The answer is taken modulo 376544743376544743.

Input Format

The first line contains three integers n,m,kn,m,k.

The second line contains mm integers, the coloring of the first row, where each color is represented by 0k10\sim k-1.

The third line contains mm integers, the coloring of the last row, where each color is represented by 0k10\sim k-1.

Output Format

Output a single integer, the answer.

The answer is taken modulo 376544743376544743.

3 2 3
1 0
1 0
3

Hint

Sample Explanation

Scheme 1

1 0
0 1
1 0

Scheme 2

1 0
0 2
1 0

Scheme 3

1 0
2 1
1 0

Constraints

Test point ID nn mm kk
11 5\le 5 2\le 2
22 107\le 10^7 105\le 10^5
33 20\le 20 3\le 3 3\le 3
44 50\le 50
565 \sim 6 100\le 100 6\le 6
787 \sim 8 50\le 50 4\le 4 4\le 4
9109 \sim 10 100\le 100 8\le 8

For 100%100\% of the testdata, n,m,k1n,m,k \ge 1.

Please note that the values of n,m,k\bm{n,m,k} do not simultaneously reach their maximum constraints.

Translated by ChatGPT 5