Language: C++

#include <vector>
#include <iostream>
#pragma warning(disable : 4996)
using namespace std;
// ------ Matrix class ------ //
class ModMatrix {
public:
	// ------ Variables ------ //
	static const int mod2 = 1000000007;
	int r, c, mod; vector<vector<int> > mat;
	// ------ Constructor ------ //
	ModMatrix() : r(0), c(0), mod(mod2) {}
	ModMatrix(int r_, int c_) : r(r_), c(c_), mod(mod2) { mat = vector<vector<int> >(r_, vector<int>(c_, 0)); }
	ModMatrix(int r_, int c_, int mod_) : r(r_), c(c_), mod(mod_) { mat = vector<vector<int> >(r_, vector<int>(c_, 0)); }
	// ------ Operator ------ //
	friend bool operator==(const ModMatrix& a, const ModMatrix& b) { return a.mat == b.mat; }
	friend bool operator!=(const ModMatrix& a, const ModMatrix& b) { return a.mat != b.mat; }
	friend ModMatrix operator+(const ModMatrix& a, const ModMatrix& b) {
		if (a.r == b.r && a.c == b.c) {
			ModMatrix c(a);
			for (int i = 0; i < a.r; i++) {
				for (int j = 0; j < a.c; j++) {
					c.mat[i][j] = (c.mat[i][j] + b.mat[i][j]) % ModMatrix::mod;
				}
			}
			return c;
		}
		return ModMatrix();
	}
	friend ModMatrix operator-(const ModMatrix& a, const ModMatrix& b) {
		if (a.r == b.r && a.c == b.c) {
			ModMatrix c(a);
			for (int i = 0; i < a.r; i++) {
				for (int j = 0; j < a.c; j++) {
					c.mat[i][j] = (c.mat[i][j] - b.mat[i][j] + ModMatrix::mod) % ModMatrix::mod;
				}
			}
			return c;
		}
		return ModMatrix();
	}
	friend ModMatrix operator*(const ModMatrix& a, const ModMatrix& b) {
		if (a.c == b.r) {
			ModMatrix c(a.r, b.c);
			for (int i = 0; i < a.r; i++) {
				for (int j = 0; j < b.c; j++) {
					for (int k = 0; k < a.c; k++) {
						c.mat[i][j] = (c.mat[i][j] + 1LL * a.mat[i][k] * b.mat[k][j]) % ModMatrix::mod;
					}
				}
			}
			return c;
		}
		return ModMatrix();
	}
	template<class Type>
	friend ModMatrix operator*(const ModMatrix& a, const Type& b) {
		ModMatrix c(a.r, a.c);
		for (int i = 0; i < a.r; i++) {
			for (int j = 0; j < a.c; j++) {
				c.mat[i][j] = 1LL * c.mat[i][j] * b % ModMatrix::mod;
			}
		}
		return c;
	}
	template<class Type>
	friend ModMatrix operator*(const Type& a, const ModMatrix& b) {
		ModMatrix c(b.r, b.c);
		for (int i = 0; i < b.r; i++) {
			for (int j = 0; j < b.c; j++) {
				c.mat[i][j] = 1LL * c.mat[i][j] * a % ModMatrix::mod;
			}
		}
		return c;
	}
	ModMatrix& operator+=(const ModMatrix& a) {
		if (a.r == r && a.c == c) {
			for (int i = 0; i < r; i++) {
				for (int j = 0; j < c; j++) {
					mat[i][j] = (mat[i][j] + a.mat[i][j]) % mod;
				}
			}
		}
		return *this;
	}
	ModMatrix& operator-=(const ModMatrix& a) {
		if (a.r == r && a.c == c) {
			for (int i = 0; i < r; i++) {
				for (int j = 0; j < c; j++) {
					mat[i][j] = (mat[i][j] - a.mat[i][j] + mod) % mod;
				}
			}
		}
		return *this;
	}
	ModMatrix& operator*=(const ModMatrix& a) {
		if (c == a.r && c == a.c) {
			vector<vector<int> > tmp(r, vector<int>(c));
			for (int i = 0; i < r; i++) {
				for (int j = 0; j < c; j++) {
					for (int k = 0; k < c; k++) {
						tmp[i][j] = (tmp[i][j] + 1LL * mat[i][k] * a.mat[k][j]) % mod;
					}
				}
			}
			for (int i = 0; i < r; i++) {
				for (int j = 0; j < c; j++) {
					mat[i][j] = tmp[i][j];
				}
			}
		}
		return *this;
	}
	template<class Type>ModMatrix& operator*=(const Type& a) {
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				mat[i][j] = 1LL * mat[i][j] * c % mod;
			}
		}
		return *this;
	}
};
// ------ Function ------ //
ModMatrix unit(int r) {
	ModMatrix res(r, r);
	for (int i = 0; i < r; i++) {
		res.mat[i][i] = 1;
	}
	return res;
}
ModMatrix power(ModMatrix a, int b) {
	if (a.r == a.c) {
		ModMatrix res = unit(a.r);
		for (int i = 30; i >= 0; i--) {
			res *= res;
			if (b & (1 << i)) {
				res *= a;
			}
		}
		return res;
	}
	return ModMatrix();
}
int N, M, A, B, C, T;
int main() {
	while (true) {
		scanf("%d%d%d%d%d%d", &N, &M, &A, &B, &C, &T);
		if (N == 0 && M == 0 && A == 0 && B == 0 && C == 0 && T == 0) break;
		ModMatrix M1(N, N, M), M2(N, 1, M);
		for (int i = 0; i < N; i++) scanf("%d", &M2.mat[i][0]);
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (i - j == 1) {
					M1.mat[i][j] = A;
				}
				else if (i == j) {
					M1.mat[i][j] = B;
				}
				else {
					M1.mat[i][j] = C;
				}
			}
		}
		M2 = power(M1, T) * M2;
		for (int i = 0; i < N; i++) {
			if (i) printf(" ");
			printf("%d\n", M2.mat[i][0]);
		}
	}
	return 0;
}

Compiler output:
a.cc: In function 'ModMatrix operator+(const ModMatrix&, const ModMatrix&)':
a.cc:23:96: error: invalid use of non-static data member 'ModMatrix::mod'
   23 |                                         c.mat[i][j] = (c.mat[i][j] + b.mat[i][j]) % ModMatrix::mod;
      |                                                                                                ^~~
a.cc:10:19: note: declared here
   10 |         int r, c, mod; vector<vector<int> > mat;
      |                   ^~~
a.cc: In function 'ModMatrix operator-(const ModMatrix&, const ModMatrix&)':
a.cc:35:95: error: invalid use of non-static data member 'ModMatrix::mod'
   35 |                                         c.mat[i][j] = (c.mat[i][j] - b.mat[i][j] + ModMatrix::mod) % ModMatrix::mod;
      |                                                                                               ^~~
a.cc:10:19: note: declared here
   10 |         int r, c, mod; vector<vector<int> > mat;
      |                   ^~~
a.cc:35:113: error: invalid use of non-static data member 'ModMatrix::mod'
   35 |                                         c.mat[i][j] = (c.mat[i][j] - b.mat[i][j] + ModMatrix::mod) % ModMatrix::mod;
      |                                                                                                                 ^~~
a.cc:10:19: note: declared here
   10 |         int r, c, mod; vector<vector<int> > mat;
      |                   ^~~
a.cc: In function 'ModMatrix operator*(const ModMatrix&, const ModMatrix&)':
a.cc:48:124: error: invalid use of non-static data member 'ModMatrix::mod'
   48 |                                                 c.mat[i][j] = (c.mat[i][j] + 1LL * a.mat[i][k] * b.mat[k][j]) % ModMatrix::mod;
      |                                                                                                                            ^~~
a.cc:10:19: note: declared here
   10 |         int r, c, mod; vector<vector<int> > mat;
      |                   ^~~
a.cc: In function 'ModMatrix operator*(const ModMatrix&, const Type&)':
a.cc:61:82: error: invalid use of non-static data member 'ModMatrix::mod'
   61 |                                 c.mat[i][j] = 1LL * c.mat[i][j] * b % ModMatrix::mod;
      |                                                                                  ^~~
a.cc:10:19: note: declared here
   10 |         int r, c, mod; vector<vector<int> > mat;
      |                   ^~~
a.cc: In function 'ModMatrix operator*(const Type&, const ModMatrix&)':
a.cc:71:82: error: invalid use of non-static data member 'ModMatrix::mod'
   71 |                                 c.mat[i][j] = 1LL * c.mat[i][j] * a % ModMatrix::mod;
      |                                                                                  ^~~
a.cc:10:19: note: declared here
   10 |         int r, c, mod; vector<vector<int> > mat;
      |                   ^~~