There is a simple directed graph
For each
Find the number of different directed paths of length
Constraints
- All values in input are integers.
is or .
Input Specification
The first line will contain 2 space separated integers
The next
Output Specification
Print the number of different directed paths of length
Sample Input 1
4 2
0 1 0 0
0 0 1 1
0 0 0 1
1 0 0 0
Sample Output 1
6
Explanation For Sample 1
There are six directed paths of length
Sample Input 2
3 3
0 1 0
1 0 1
0 0 0
Sample Output 2
3
Explanation For Sample 2
There are three directed paths of length
Sample Input 3
6 2
0 0 0 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 1 0
0 0 0 0 0 1
0 0 0 0 0 0
Sample Output 3
1
Explanation For Sample 3
There is one directed path of length
Sample Input 4
1 1
0
Sample Output 4
0
Sample Input 5
10 1000000000000000000
0 0 1 1 0 0 0 1 1 0
0 0 0 0 0 1 1 1 0 0
0 1 0 0 0 1 0 1 0 1
1 1 1 0 1 1 0 1 1 0
0 1 1 1 0 1 0 1 1 1
0 0 0 1 0 0 1 0 1 0
0 0 0 1 1 0 0 1 0 1
1 0 0 0 1 0 1 0 0 0
0 0 0 0 0 1 0 0 0 0
1 0 1 1 1 0 1 1 1 0
Sample Output 5
957538352
Explanation For Sample 5
Be sure to print the count modulo
Comments