Language: C++

template <typename T> class Matrix {
private:
  vector<vector<T>> matrix;
  template<typename U> using ET = enable_if<is_floating_point<U>::value>;
  template<typename U> using EF = enable_if<!is_floating_point<U>::value>;
  template<typename U, typename ET<U>::type* = nullptr> static constexpr bool is_zero (const U& x) { return abs(x) < 1e-8; }
  template<typename U, typename EF<U>::type* = nullptr> static constexpr bool is_zero (const U& x) { return x == U(0); }
public:
  constexpr Matrix () {}
  constexpr Matrix (int h, int w) : matrix(vector<vector<T>>(h, vector<T>(w))) {}
  constexpr Matrix (const vector<vector<T>>& mat) : matrix(mat) {}
  constexpr Matrix (const Matrix<T>& mat) : matrix(mat.matrix) {}

  constexpr size_t height () { return (int) matrix.size(); }
  constexpr size_t width () { assert(!empty()); return (int) matrix[0].size(); }
  constexpr bool empty() { return matrix.empty(); }
  
  vector<T>& operator[] (size_t row) { assert(matrix.size() > row); return matrix[row]; }
  const vector<T>& operator[] (size_t row) const { assert(matrix.size() > row); return matrix[row]; }

  static Matrix identity (int n) {
    Matrix res(n, n);
    for (int i = 0; i < n; ++i) res[i][i] = T(1);
    return res;
  }
  Matrix identity () { assert(height() == width()); return identity(height()); };

  constexpr Matrix<T>& operator= (const Matrix<T>& lhs) & noexcept {
    int h = lhs.matrix.size();
    int w = lhs.matrix[0].size();
    matrix = vector<vector<T>>(h, vector<T>(w, T()));
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) matrix[i][j] = lhs.matrix[i][j];
    return *this; 
  }
  constexpr Matrix<T>& operator= (const vector<vector<T>>& lhs) & noexcept { return *this = Matrix(lhs); }

  constexpr Matrix<T>& operator+= (const Matrix<T>& lhs) noexcept {
    assert(height() == lhs.height());
    assert(width() == lhs.width());
    for (int i = 0; i < height(); ++i) for (int j = 0; j < width(); ++j) matrix[i][j] += lhs[i][j];
    return (*this);
  }
  constexpr Matrix<T>& operator+= (const vector<vector<T>>& lhs) noexcept { return *this += Matrix(lhs); }

  constexpr Matrix<T>& operator-= (const Matrix<T>& lhs) noexcept {
    assert(height() == lhs.height());
    assert(width() == lhs.width());
    for (int i = 0; i < height(); ++i) for (int j = 0; j < width(); ++j) matrix[i][j] -= lhs[i][j];
    return (*this);
  }
  constexpr Matrix<T>& operator-= (const vector<vector<T>>& lhs) noexcept { return *this -= Matrix(lhs); }

  constexpr Matrix<T>& operator*= (Matrix<T>& lhs) noexcept {
    assert(width() == lhs.height());
    Matrix res(height(), lhs.width());
    for (int i = 0; i < (int) height(); ++i) for (int j = 0; j < (int) lhs.width(); ++j) for (int k = 0; k < (int) width(); k++) {
      res[i][j] += matrix[i][k] * lhs[k][j];
    }
    matrix.swap(res.matrix);
    return (*this);
  }
  constexpr Matrix<T>& operator*= (const vector<vector<T>>& lhs) noexcept { return *this *= Matrix(lhs); }

  friend constexpr bool operator==(const Matrix<T>& lhs, const Matrix<T>& rhs) noexcept { return lhs.matrix == rhs.matrix; }
  friend constexpr bool operator==(const Matrix<T>& lhs, const vector<vector<T>>& rhs) noexcept { return lhs == Matrix(rhs); }
  friend constexpr bool operator==(const vector<vector<T>>& lhs, const Matrix<T>& rhs) noexcept { return Matrix(lhs) == rhs; }

  friend constexpr Matrix<T> operator+(const Matrix<T>& lhs, const Matrix<T>& rhs) noexcept { return Matrix(lhs) += rhs; }
  friend constexpr Matrix<T> operator+(const Matrix<T>& lhs, const vector<vector<T>>& rhs) noexcept { return Matrix(lhs) += rhs; }
  friend constexpr Matrix<T> operator+(const vector<vector<T>>& lhs, const Matrix<T>& rhs) noexcept { return Matrix(lhs) += rhs; }

  friend constexpr Matrix<T> operator-(const Matrix<T>& lhs, const Matrix<T>& rhs) noexcept { return Matrix(lhs) -= rhs; }
  friend constexpr Matrix<T> operator-(const Matrix<T>& lhs, const vector<vector<T>>& rhs) noexcept { return Matrix(lhs) -= rhs; }
  friend constexpr Matrix<T> operator-(const vector<vector<T>>& lhs, const Matrix<T>& rhs) noexcept { return Matrix(lhs) -= rhs; }

  friend constexpr Matrix<T> operator*(const Matrix<T>& lhs, const Matrix<T>& rhs) noexcept { return Matrix(lhs) *= rhs; }
  friend constexpr Matrix<T> operator*(const Matrix<T>& lhs, const vector<vector<T>>& rhs) noexcept { return Matrix(lhs) *= rhs; }
  friend constexpr Matrix<T> operator*(const vector<vector<T>>& lhs, const Matrix<T>& rhs) noexcept { return Matrix(lhs) *= rhs; }

  template <typename U> Matrix<T> power(U n) {
    Matrix x(*this), res = identity(height());
    while (n) {
      if (n & 1) res *= x;
      x *= x;
      n >>= 1;
    }
    return res;
  }
  T determinant() {
    Matrix a(*this);
    assert(a.height() == a.width());
    T res = 1;
    for (int i = 0; i < width(); ++i) {
      int pivot = -1;
      for (int j = i; j < width(); ++j) if (!is_zero(a[j][i])) pivot = j;
      if (pivot == -1) return T(0);
      if (i != pivot) {
        res *= -1;
        swap(a[i], a[pivot]);
      }
      res *= a[i][i];
      T div = a[i][i];
      for (int j = 0; j < width(); ++j) a[i][j] /= div;
      for (int j = i + 1; j < width(); ++j) {
        T b = a[j][i];
        for (int k = 0; k < width(); ++k) {
          a[j][k] -= a[i][k] * b;
        }
      }
    }
    return res;
  }
};

signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  long long k;
  cin >> k;
  Matrix<mint> mat(n, n);
  for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> mat[i][j];
  Matrix<mint> res = mat.power(k);
  mint ans = 0;
  for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) ans += res[i][j];
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc:3:3: error: 'vector' does not name a type
    3 |   vector<vector<T>> matrix;
      |   ^~~~~~
a.cc:4:35: error: 'enable_if' does not name a type
    4 |   template<typename U> using ET = enable_if<is_floating_point<U>::value>;
      |                                   ^~~~~~~~~
a.cc:5:35: error: 'enable_if' does not name a type
    5 |   template<typename U> using EF = enable_if<!is_floating_point<U>::value>;
      |                                   ^~~~~~~~~
a.cc:6:33: error: expected nested-name-specifier before 'ET'
    6 |   template<typename U, typename ET<U>::type* = nullptr> static constexpr bool is_zero (const U& x) { return abs(x) < 1e-8; }
      |                                 ^~
a.cc:6:35: error: expected '>' before '<' token
    6 |   template<typename U, typename ET<U>::type* = nullptr> static constexpr bool is_zero (const U& x) { return abs(x) < 1e-8; }
      |                                   ^
a.cc:7:33: error: expected nested-name-specifier before 'EF'
    7 |   template<typename U, typename EF<U>::type* = nullptr> static constexpr bool is_zero (const U& x) { return x == U(0); }
      |                                 ^~
a.cc:7:35: error: expected '>' before '<' token
    7 |   template<typename U, typename EF<U>::type* = nullptr> static constexpr bool is_zero (const U& x) { return x == U(0); }
      |                                   ^
a.cc:7:79: error: 'template<class T> template<class U, <declaration error> > static constexpr bool Matrix<T>::is_zero(const U&)' cannot be overloaded with 'template<class T> template<class U, <declaration error> > static constexpr bool Matrix<T>::is_zero(const U&)'
    7 |   template<typename U, typename EF<U>::type* = nullptr> static constexpr bool is_zero (const U& x) { return x == U(0); }
      |                                                                               ^~~~~~~
a.cc:6:79: note: previous declaration 'template<class T> template<class U, <declaration error> > static constexpr bool Matrix<T>::is_zero(const U&)'
    6 |   template<typename U, typename ET<U>::type* = nullptr> static constexpr bool is_zero (const U& x) { return abs(x) < 1e-8; }
      |                                                                               ^~~~~~~
a.cc:11:27: error: 'vector' does not name a type
   11 |   constexpr Matrix (const vector<vector<T>>& mat) : matrix(mat) {}
      |                           ^~~~~~
a.cc:11:33: error: expected ',' or '...' before '<' token
   11 |   constexpr Matrix (const vector<vector<T>>& mat) : matrix(mat) {}
      |                                 ^
a.cc:14:13: error: 'size_t' does not name a type
   14 |   constexpr size_t height () { return (int) matrix.size(); }
      |             ^~~~~~
a.cc:1:1: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
  +++ |+#include <cstddef>
    1 | template <typename T> class Matrix {
a.cc:15:13: error: 'size_t' does not name a type
   15 |   constexpr size_t width () { assert(!empty()); return (int) matrix[0].size(); }
      |             ^~~~~~
a.cc:15:13: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
a.cc:18:3: error: 'vector' does not name a type
   18 |   vector<T>& operator[] (size_t row) { assert(matrix.size() > row); return matrix[row]; }
      |   ^~~~~~
a.cc:19:9: error: 'vector' does not name a type
   19 |   const vector<T>& operator[] (size_t row) const { assert(matrix.size() > row); return matrix[row]; }
      |         ^~~~~~
a.cc:35:41: error: 'vector' does not name a type
   35 |   constexpr Matrix<T>& operator= (const vector<vector<T>>& lhs) & noexcept { return *this = Matrix(lhs); }
      |                                         ^~~~~~
a.cc:35:47: error: expected ',' or '...' before '<' token
   35 |   constexpr Matrix<T>& operator= (const vector<vector<T>>& lhs) & noexcept { return *this = Matrix(lhs); }
      |                                               ^
a.cc:43:42: error: 'vector' does not name a type
   43 |   constexpr Matrix<T>& operator+= (const vector<vector<T>>& lhs) noexcept { return *this += Matrix(lhs); }
      |                                          ^~~~~~
a.cc:43:48: error: expected ',' or '...' before '<' token
   43 |   constexpr Matrix<T>& operator+= (const vector<vector<T>>& lhs) noexcept { return *this += Matrix(lhs); }
      |                                                ^
a.cc:51:42: error: 'vector' does not name a type
   51 |   constexpr Matrix<T>& operator-= (const vector<vector<T>>& lhs) noexcept { return *this -= Matrix(lhs); }
      |                                          ^~~~~~
a.cc:51:48: error: expected ',' or '...' before '<' token
   51 |   constexpr Matrix<T>& operator-= (const vector<vector<T>>& lhs) noexcept { return *this -= Matrix(lhs); }
      |                                                ^
a.cc:62:42: error: 'vector' does not name a type
   62 |   constexpr Matrix<T>& operator*= (const vector<vector<T>>& lhs) noexcept { return *this *= Matrix(lhs); }
      |                                          ^~~~~~
a.cc:62:48: error: expected ',' or '...' before '<' token
   62 |   constexpr Matrix<T>& operator*= (const vector<vector<T>>& lhs) noexcept { return *this *= Matrix(lhs); }
      |                                                ^
a.cc:65:64: error: 'vector' does not name a type
   65 |   friend constexpr bool operator==(const Matrix<T>& lhs, const vector<vector<T>>& rhs) noexcept { return lhs == Matrix(rhs); }
      |                                                                ^~~~~~
a.cc:65:70: error: expected ',' or '...' before '<' token
   65 |   friend constexpr bool operator==(const Matrix<T>& lhs, const vector<vector<T>>& rhs) noexcept { return lhs == Matrix(rhs); }
      |                                                                      ^
a.cc:66:42: error: 'vector' does not name a type
   66 |   friend constexpr bool operator==(const vector<vector<T>>& lhs, const Matrix<T>& rhs) noexcept { return Matrix(lhs) == rhs; }
      |                                          ^~~~~~
a.cc:66:48: error: expected ',' or '...' before '<' token
   66 |   friend constexpr bool operator==(const vector<vector<T>>& lhs, const Matrix<T>& rhs) noexcept { return Matrix(lhs) == rhs; }
      |                                                ^
a.cc:66:25: error: 'constexpr bool operator==(int)' must have an argument of class or enumerated type
   66 |   friend constexpr bool operator==(const vector<vector<T>>& lhs, const Matrix<T>& rhs) noexcept { return Matrix(lhs) == rhs; }
      |                         ^~~~~~~~
a.cc:69:68: error: 'vector' does not name a type
   69 |   friend constexpr Matrix<T> operator+(const Matrix<T>& lhs, const vector<vector<T>>& rhs) noexcept { return Matrix(lhs) += rhs; }
      |                                                                    ^~~~~~
a.cc:69:74: error: expected ',' or '...' before '<' token
   69 |   friend constexpr Matrix<T> operator+(const Matrix<T>& lhs, const vector<vector<T>>& rhs) noexcept { return Matrix(lhs) += rhs; }
      |                                                                          ^
a.cc:70:46: error: 'vector' does not name a type
   70 |   friend constexpr Matrix<T> operator+(const vector<vector<T>>& lhs, const Matrix<T>& rhs) noexcept { return Matrix(lhs) += rhs; }
      |                                              ^~~~~~
a.cc:70:52: error: expected ',' or '...' before '<' token
   70 |   friend constexpr Matrix<T> operator+(const vector<vector<T>>& lhs, const Matrix<T>& rhs) noexcept { return Matrix(lhs) += rhs; }
      |                                                    ^
a.cc:70:30: error: 'constexpr Matrix<T> operator+(int)' must have an argument of class or enumerated type
   70 |   friend constexpr Matrix<T> operator+(const vector<vector<T>>& lhs, const Matrix<T>& rhs) noexcept { return Matrix(lhs) += rhs; }
      |                              ^~~~~~~~
a.cc:73:68: error: 'vector' does not name a type
   73 |   friend constexpr Matrix<T> operator-(const Matrix<T>& lhs, const vector<vector<T>>& rhs) noexcept { return Matrix(lhs) -= rhs; }
      |                                                                    ^~~~~~
a.cc:73:74: error: expected ',' or '...' before '<' token
   73 |   friend constexpr Matrix<T> operator-(const Matrix<T>& lhs, const vector<vector<T>>& rhs) noexcept { return Matrix(lhs) -= rhs; }
      |                                                                          ^
a.cc:74:46: error: 'vector' does not name a type
   74 |   friend constexpr Matrix<T> operator-(const vector<vector<T>>& lhs, const Matrix<T>& rhs) noexcept { return Matrix(lhs) -= rhs; }
      |                                              ^~~~~~
a.cc:74:52: error: expected ',' or '...' before '<' token
   74 |   friend constexpr Matrix<T> operator-(const vector<vector<T>>& lhs, const Matrix<T>& rhs) noexcept { return Matrix(lhs) -= rhs; }
      |                                                    ^
a.cc:74:30: error: 'constexpr Matrix<T> operator-(int)' must have an argument of class or enumerated type
   74 |   friend constexpr Matrix<T> operator-(const vector<vector<T>>& lhs, const Matrix<T>& rhs) noexcept { return Matrix(lhs) -= rhs; }
      |                              ^~~~~~~~
a.cc:77:68: error: 'vector' does not name a type
   77 |   friend constexpr Matrix<T> operator*(const Matrix<T>& lhs, const vector<vector<T>>& rhs) noexcept { return Matrix(lhs) *= rhs; }
      |                                                                    ^~~~~~
a.cc:77:74: error: expected ',' or '...' before '<' token
   77 |   friend constexpr Matrix<T> operator*(const Matrix<T>& lhs, const vector<vector<T>>& rhs) noexcept { return Matrix(lhs) *= rhs; }
      |                                                                          ^
a.cc:78:46: error: 'vector' does not name a type
   78 |   friend constexpr Matrix<T> operator*(const vector<vector<T>>& lhs, const Matrix<T>& rhs) noexcept { return Matrix(lhs) *= rhs; }
      |                                              ^~~~~~
a.cc:78:52: error: expected ',' or '...' before '<' token
   78 |   friend constexpr Matrix<T> oper