#include using namespace std; template vector> multima(vector> &A,vector> &B){ assert(A.at(0).size() == B.size() && B.size()); int H = A.size(),W = B.at(0).size(); vector> ret(H,vector(W)); for(int i=0; i vector> Powmat(vector> A,vector> B,long long N){ //return A^N*B ABは行列; //n*n行列A n*1行列Bと想定 O(n^3*logN). assert(A.size() && A.size() == A.at(0).size() && N >= 0); while(N){ if(N&1) B = multima(A,B); A = multima(A,A); N >>= 1; } return B; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); long long N,M; cin >> N >> M; vector T(N); for(auto &t : T) cin >> t; vector> A(N,vector(N)),B(N); for(auto &h : A) for(auto &w : h) cin >> w; for(int i=0; i