#dpr. [dp_r]Walk

[dp_r]Walk

Problem Statement

There is a simple directed graph GG with NN vertices, numbered 1,2,ldots,N1, 2, \\ldots, N.

For each ii and jj (1leqi,jleqN1 \\leq i, j \\leq N), you are given an integer ai,ja_{i, j} that represents whether there is a directed edge from Vertex ii to jj. If ai,j=1a_{i, j} = 1, there is a directed edge from Vertex ii to jj; if ai,j=0a_{i, j} = 0, there is not.

Find the number of different directed paths of length KK in GG, modulo 109+710^9 + 7. We will also count a path that traverses the same edge multiple times.

Constraints

  • All values in input are integers.
  • 1leqNleq501 \\leq N \\leq 50
  • 1leqKleq10181 \\leq K \\leq 10^{18}
  • ai,ja_{i, j} is 00 or 11.
  • ai,i=0a_{i, i} = 0

Input

Input is given from Standard Input in the following format:

NN KK a1,1a_{1, 1} ldots\\ldots a1,Na_{1, N} :: aN,1a_{N, 1} ldots\\ldots aN,Na_{N, N}

Output

Print the number of different directed paths of length KK in GG, modulo 109+710^9 + 7.


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

GG is drawn in the figure below:

There are six directed paths of length 22:

  • 112233
  • 112244
  • 223344
  • 224411
  • 334411
  • 441122

Sample Input 2

3 3
0 1 0
1 0 1
0 0 0

Sample Output 2

3

GG is drawn in the figure below:

There are three directed paths of length 33:

  • 11221122
  • 22112211
  • 22112233

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

GG is drawn in the figure below:

There is one directed path of length 22:

  • 445566

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

Be sure to print the count modulo 109+710^9 + 7.