#include using namespace std; using ll=long long; using ull=unsigned long long; using P=pair; templateusing minque=priority_queue,greater>; templatebool chmax(T &a,const T &b){return (abool chmin(T &a,const T &b){return (a>b?(a=b,true):false);} templateistream &operator>>(istream &is,pair&p){is>>p.first>>p.second;return is;} templateistream &operator>>(istream &is,tuple&a){is>>std::get<0>(a)>>std::get<1>(a)>>std::get<2>(a);return is;} templateistream &operator>>(istream &is,array&a){for(auto&i:a)is>>i;return is;} templateistream &operator>>(istream &is,vector &a){for(auto &i:a)is>>i;return is;} templatevoid operator++(pair&a,int n){a.first++,a.second++;} templatevoid operator--(pair&a,int n){a.first--,a.second--;} templatevoid operator++(vector&a,int n){for(auto &i:a)i++;} templatevoid operator--(vector&a,int n){for(auto &i:a)i--;} #define overload3(_1,_2,_3,name,...) name #define rep1(i,n) for(int i=0;i<(int)(n);i++) #define rep2(i,l,r) for(int i=(int)(l);i<(int)(r);i++) #define rep(...) overload3(__VA_ARGS__,rep2,rep1)(__VA_ARGS__) #define reps(i,l,r) rep2(i,l,r) #define all(x) x.begin(),x.end() #define pcnt(x) __builtin_popcountll(x) #define fin(x) return cout<<(x)<<'\n',static_cast(0) #define yn(x) cout<<((x)?"Yes\n":"No\n") #define uniq(x) sort(all(x)),x.erase(unique(all(x)),x.end()) template inline int fkey(vector&z,T key){return lower_bound(z.begin(),z.end(),key)-z.begin();} ll myceil(ll a,ll b){return (a+b-1)/b;} template auto vec(const int (&d)[n],const T &init=T()){ if constexpr (id(d,init)); else return init; } #ifdef LOCAL #include #define SWITCH(a,b) (a) #else #define debug(...) static_cast(0) #define debugg(...) static_cast(0) #define SWITCH(a,b) (b) templateostream &operator<<(ostream &os,const pair&p){os<>testcase; for(int i=0;i struct semiring { T x; semiring() : x(I0()) {} semiring(T y) : x(y) {} static T id0() { return I0(); } static T id1() { return I1(); } semiring &operator+=(const semiring &p) { if (x == I0()) return *this = p; if (p.x == I0()) return *this; return *this = add(x, p.x); } semiring &operator*=(const semiring &p) { if (x == I0() || p.x == I0()) return *this = I0(); if (x == I1()) return *this = p; if (p.x == I1()) return *this; return *this = mul(x, p.x); } semiring operator+(const semiring &p) const { return semiring(*this) += p; } semiring operator*(const semiring &p) const { return semiring(*this) *= p; } bool operator==(const semiring &p) const { return x == p.x; } bool operator!=(const semiring &p) const { return x != p.x; } friend ostream &operator<<(ostream &os, const semiring &p) { return os << p.x; } }; template struct Mat { using Array = vector>; Array A; int N; Mat() { // for (int i = 0; i < N; i++) A[i].fill(rig::id0()); } Mat(vector>a){ N=a.size(); A.resize(N,vector(N)); rep(i,a.size())rep(j,a.size())A[i][j]=a[i][j]; } int height() const { return N; } int width() const { return N; } inline const vector &operator[](int k) const { return A[k]; } inline vector &operator[](int k) { return A[k]; } static Mat I(int N) { Mat m; m.A=vector>(N,vector(N)); m.N=N; for (int i = 0; i < N; i++) m[i][i] = rig::id1(); return m; } Mat &operator+=(const Mat &B) { for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) A[i][j] += B[i][j]; return (*this); } Mat &operator*=(const Mat &B) { Mat C; C.A=vector>(N,vector(N)); C.N=N; for (int i = 0; i < N; i++){ for (int k = 0; k < N; k++){ for (int j = 0; j < N; j++){ C[i][j] += A[i][k] * B[k][j]; } } } swap(A,C.A); return (*this); } Mat &operator^=(long long k) { Mat B = Mat::I(N); for (; k; *this *= *this, k >>= 1){ debug('U'); if (k & 1) B *= *this; debug('U'); } A.swap(B.A); return (*this); } Mat operator+(const Mat &B) const { return (Mat(*this) += B); } Mat operator*(const Mat &B) const { return (Mat(*this) *= B); } Mat operator^(long long k) const { return (Mat(*this) ^= k); } friend ostream &operator<<(ostream &os, Mat &p) { int N=p.A.size(); for (int i = 0; i < N; i++) { os << "["; for (int j = 0; j < N; j++) { os << p[i][j].x << (j == N - 1 ? "]\n" : ","); } } return (os); } }; constexpr ll infLL=1e18; using U = long long; U add(U a, U b) { return max(a, b); } U mul(U a, U b) { return a + b; } U i0() { return -infLL; } U i1() { return 0; } using rig = semiring; //https://nyaannyaan.github.io/library/math/semiring.hpp.html void SOLVE(){ int n; ll m; cin>>n>>m; vectort(n); cin>>t; vector>a(n,vector(n)); cin>>a; Mat mat(a); mat^=m; rep(i,n){ ll ans=i0(); rep(j,n)ans=add(ans,mul(t[j],mat[j][i].x)); cout<