Buggy python submission (verdict: Runtime Error):
from numpy import int_, eye

mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())
A = int_(A).reshape(N, N)

ans = eye(N, dtype=int_)
while K:
    if K & 1:
        ans = (ans.dot(A)) % mod
    A = A.dot(A) % mod
    K //= 2

print(ans.sum() % mod)

Fixed submission:
from numpy import array, eye

mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())
A = array(A, dtype=object).reshape(N, N)

ans = eye(N, dtype=object)
while K:
    if K & 1:
        ans = (ans.dot(A)) % mod
    A = A.dot(A) % mod
    K //= 2

print(ans.sum() % mod)

Buggy python submission (verdict: Runtime Error):
from numpy import int_

mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())
A = int_(A).reshape(N, N)

K //= 2
ans = A
while K:
    if K & 1:
        ans = (ans @ A) % mod
    A = (A @ A) % mod
    K //= 2

print(ans.sum())

Fixed submission:
from numpy import array, eye

mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())
A = array(A, dtype=object).reshape(N, N)

ans = eye(N, dtype=object)
while K:
    if K & 1:
        ans = (ans.dot(A)) % mod
    A = A.dot(A) % mod
    K //= 2

print(ans.sum() % mod)

Buggy python submission (verdict: Time Limit Exceeded):
from numpy.linalg import matrix_power
from numpy import matrix

class mint:
    def __init__(self, i, mod=10 ** 9 + 7):
        self.mod = mod
        self.i = i % mod
    def __add__(self, other):
        return mint(self.i + other.i)
    def __mul__(self, other):
        return mint(self.i * other.i)
    def __str__(self):
        return str(self.i)

N, K = map(int, input().split())
A = matrix([[mint(int(i)) for i in input().split()] for _ in range(N)])

print(matrix_power(A, K).sum())

Fixed submission:
from numpy import array, eye

mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())
A = array(A, dtype=object).reshape(N, N)

ans = eye(N, dtype=object)
while K:
    if K & 1:
        ans = (ans.dot(A)) % mod
    A = A.dot(A) % mod
    K //= 2

print(ans.sum() % mod)

Buggy python submission (verdict: Time Limit Exceeded):
from numpy.linalg import matrix_power
from numpy import mat

class mint:
    def __init__(self, i, mod=10 ** 9 + 7):
        self.mod = mod
        self.i = i % mod
    def __add__(self, other):
        return mint(self.i + other.i)
    def __mul__(self, other):
        return mint(self.i * other.i)
    def __str__(self):
        return str(self.i)

N, K = map(int, input().split())
A = mat([[mint(int(i)) for i in input().split()] for _ in range(N)])

print(matrix_power(A, K).sum())

Fixed submission:
from numpy import array, eye

mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())
A = array(A, dtype=object).reshape(N, N)

ans = eye(N, dtype=object)
while K:
    if K & 1:
        ans = (ans.dot(A)) % mod
    A = A.dot(A) % mod
    K //= 2

print(ans.sum() % mod)

Buggy python submission (verdict: Time Limit Exceeded):
from numpy.linalg import matrix_power

mod = 10 ** 9 + 7
class mint:
    def __init__(self, i):
        self.i = i % mod
    def __add__(self, other):
        return mint(self.i + other.i)
    def __mul__(self, other):
        return mint(self.i * other.i)
    def __str__(self):
        return str(self.i)

N, K = map(int, input().split())
A = [[mint(int(i)) for i in input().split()] for _ in range(N)]

print(matrix_power(A, K).sum())

Fixed submission:
from numpy import array, eye

mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())
A = array(A, dtype=object).reshape(N, N)

ans = eye(N, dtype=object)
while K:
    if K & 1:
        ans = (ans.dot(A)) % mod
    A = A.dot(A) % mod
    K //= 2

print(ans.sum() % mod)