#DPR. Walk

Walk

Score : 100100 points

Problem Statement

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

For each ii and jj (1i,jN1 \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.
  • 1N501 \leq N \leq 50
  • 1K10181 \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 a1,Na_{1, N}

::

aN,1a_{N, 1} \ldots aN,Na_{N, N}

Output

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

4 2
0 1 0 0
0 0 1 1
0 0 0 1
1 0 0 0
6

GG is drawn in the figure below:

There are six directed paths of length 22:

  • 112233
  • 112244
  • 223344
  • 224411
  • 334411
  • 441122
3 3
0 1 0
1 0 1
0 0 0
3

GG is drawn in the figure below:

There are three directed paths of length 33:

  • 11221122
  • 22112211
  • 22112233
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
1

GG is drawn in the figure below:

There is one directed path of length 22:

  • 445566
1 1
0
0
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
957538352

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