ll k; int N = 6; // matrix size structmatrix { ll g[N][N]; matrix operator=(const matrix &b) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { g[i][j] = b.g[i][j]; } } return *this; } }a,b;
matrix operator*(const matrix &a, const matrix &b) { matrix c; memset(c.g, 0, sizeof(c.g)); for (ll i = 0; i < N; i++) for (ll k = 0; k < N; k++) { if (a.g[i][k] == 0) { continue; } for (ll j = 0; j <N; j++) c.g[i][j] = (c.g[i][j] + a.g[i][k]*b.g[k][j] %m) % m; } return c; }
matrix pow(matrix a, ll b) { matrix ans; memset(ans.g, 0, sizeof(ans.g)); for (int i = 0; i < N; i++) { ans.g[i][i] = 1; } while (b) { if (b & 1) ans = ans * a; a = a * a; b >>= 1; } return ans; }