Language: C++

#include <iostream>
#include <algorithm>
 
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 constructor 'mat::mat(int, int)':
a.cc:14:9: error: 'memset' was not declared in this scope
   14 |         memset(mx, 0, sizeof mx);
      |         ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include <algorithm>
  +++ |+#include <cstring>
    3 | 
a.cc: In member function 'void mat::setval(int, int, int)':
a.cc:18:9: error: 'assert' was not declared in this scope
   18 |         assert(x < this->x && y < this->y);
      |         ^~~~~~
a.cc:3:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    2 | #include <algorithm>
  +++ |+#include <cassert>
    3 | 
a.cc: In member function 'long long int mat::getval(int, int)':
a.cc:27:9: error: 'assert' was not declared in this scope
   27 |         assert(x < this->x);
      |         ^~~~~~
a.cc:27: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:33:9: error: 'assert' was not declared in this scope
   33 |         assert(this->y == tren.x);
      |         ^~~~~~
a.cc:33:9: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'