You have a
- Push
onto the first column of . All columns move to the right by one, with the last column being deleted. Formally, if is the grid after the operation is completed, then for all , and for all , . - Push
onto the first row of . All rows move down by one, with the last row being deleted. Formally, if is the grid after the operation is completed, then for all , and for all , .
What is the number of distinct grids with no
Constraints
Subtask 1 [30%]
Subtask 2 [40%]
Subtask 3 [30%]
No additional constraints.
Input Specification
The first line contains a single integer,
The second line will contain
The third line will contain
Output Specification
Output a single integer representing the number of distinct grids that can be created modulo
Sample Input 1
Copy
1
1
1
Sample Output 1
Copy
1
Sample Input 2
Copy
1
1
2
Sample Output 2
Copy
2
Sample Input 3
Copy
2
1 1
1 2
Sample Output 3
Copy
3
Comments