Language: C++

#include <iostream>
#include <algorithm>
#include <cstring>
 
using namespace std;
const long long mod = 1000000007;
 
struct mat {
    long long mx[60][60];
    int x, y;
 
    mat(int x, int y) {
        this->x = x;
        this->y = y;
        memset(mx, 0, sizeof mx);
    }
 
    void setval(int x, int y, int val) {
        assert(x < this->x && y < this->y);
        this->mx[x][y] = val;
        //printf("debug: %d\n", this->mx[x][y]);
        //this->print();
    }
 
    long long getval(int x, int y) {
        //printf("%d %d -> %d %d\n", x, y, this->x, this->y); 
        //fflush(stdout);
        assert(x < this->x);
        assert(y < this->y);
        return this->mx[x][y];
    }
 
    mat operator * (mat tren) {
        assert(this->y == tren.x);
        mat ne = mat(this->x, tren.y);
 
        for (int i = 0; i < this->x; i++) {
            for (int j = 0; j < tren.y; j++) {
                long long ac = 0;
                for (int k = 0; k < this->y; k++)
                    ac += ((this->mx[i][k] * tren.getval(k, j)) % mod), ac %= mod;
                ne.setval(i, j, ac);
            }
        }
        return ne;
    }
 
    void operator = (mat tren) {
        this->x = tren.x;
        this->y = tren.y;
 
        for (int i = 0; i < this->x; i++)
            for (int j = 0; j < this->y; j++)
                this->mx[i][j] = tren.getval(i, j);
    }
 
    void print() {
        for (int i = 0; i < this->x; i++) {
            for (int j = 0; j < this->y; j++)
                printf("%d ", this->mx[i][j]);
            printf("\n");
        }
        printf("\n");
    }
};
 
int n;
long long k;
long long get(mat &a, mat &b) {
    mat cp(n, n);
    for (int i = 0; i < n; i++)
    	cp.setval(i, i, 1);
    while (k > 0) {
    	if (k & 1) cp = cp * b;
    	b = b * b;
    	k /= 2;
	}
	a = a * cp;
	long long sol = 0;
	for (int i = 0; i < n; i++)
		sol += a.getval(0, i), sol %= mod;
	return sol;
}
 
int main() {
    scanf("%d%lld", &n, &k);
    mat pot(n, n);
    for (int i = 0; i < n; i++)
    	for (int j = 0; j < n; j++)
    		scanf("%lld", &pot.mx[i][j]);
    
    mat kol(1, n);
	for (int i = 0; i < n; i++)
		kol.setval(0, i, 1);
    printf("%lld\n", get(kol, pot));
    //system("pause");
    return 0;
}


Compiler output:
a.cc: In member function 'void mat::setval(int, int, int)':
a.cc:19:9: error: 'assert' was not declared in this scope
   19 |         assert(x < this->x && y < this->y);
      |         ^~~~~~
a.cc:4:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    3 | #include <cstring>
  +++ |+#include <cassert>
    4 | 
a.cc: In member function 'long long int mat::getval(int, int)':
a.cc:28:9: error: 'assert' was not declared in this scope
   28 |         assert(x < this->x);
      |         ^~~~~~
a.cc:28:9: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
a.cc: In member function 'mat mat::operator*(mat)':
a.cc:34:9: error: 'assert' was not declared in this scope
   34 |         assert(this->y == tren.x);
      |         ^~~~~~
a.cc:34:9: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'