Entanglement
Time limit3sMemory limit256 MB
Count pairs of arrays A (length N) and B (length M) with values from 1 to K such that every cell C[i][j] equals A[i] or B[j].
- Level
Hard9 of 10
- Topics
- Combinatorics, Graph, Math
- Solved
- No attempts yet
Problem
Consider an array of length and an array of length . An entanglement of these two arrays is an matrix such that for every and , at least one of or holds.
You are given a matrix of size and an integer . Count the pairs of arrays such that:
- has length .
- has length .
- Every element of and is in .
- is an entanglement of and .
Print the count modulo .
Input
The first line contains three integers , , and (, ).
Each of the next lines contains integers separated by spaces. The -th number on the -th of these lines is .
Output
Print a single integer: the number of pairs modulo .