#ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif #include #include #include using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; //using mint = modint1000000007; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repu(i, s, t) for (int i = (int)(s); i < (int)(t); i++) #define repd(i, s, t) for (int i = (int)(s)-1; i >= (int)(t); i--) #define all(v) v.begin(), v.end() void _u() { cerr << endl; } template void _u(H&& h, T&&... t) { cerr << h << ", "; _u(move(t)...); } #define U(...) { cerr << #__VA_ARGS__ << ": "; _u(__VA_ARGS__); } template bool chmax(T &a, const T b) { if(a >= b) return false; a = b; return true; } template bool chmin(T &a, const T b) { if(a <= b) return false; a = b; return true; } template istream& operator>>(istream &in, vector &a) { for(T &x: a) in >> x; return in; } template ostream& operator<<(ostream &out, const vector &a) { for(const T &x: a) out << x << ' '; return out; } const int di[] = {1, 0, -1, 0, 1, 1, -1, -1, 0}; const int dj[] = {0, 1, 0, -1, -1, 1, 1, -1, 0}; const ll INF = 1e18; template struct Matrix { vector> mat; int m, n; Matrix(initializer_list> init) { mat.resize(0); for(const auto &row : init) { mat.emplace_back(row); } m = mat.size(); n = mat.empty() ? 0 : mat[0].size(); } Matrix(vector> &mat_): mat(mat_), m(int(mat_.size())), n(mat.empty() ? 0 : int(mat_[0].size())) {} Matrix(int x, int y, T val):mat(vector(x, vector(y, val))), m(x), n(y) {} Matrix(int x, int y):mat(vector(x, vector(y))), m(x), n(y) {} Matrix(int x): m(x), n(x) { mat = vector(x, vector (x, -INF)); rep(i, x) mat[i][i] = 0; } vector &operator[](int x) { return mat[x]; } Matrix &operator+=(const Matrix &other) { assert(m == other.m && n == other.n); rep(i, m) rep(j, n) *this[i][j] += other[i][j]; return *this; } Matrix operator+(const Matrix &other) { return Matrix(*this) += other; } Matrix &operator*=(const Matrix &other) { return *this = *this * other; } Matrix operator*(const Matrix &other) { assert(n == other.m); Matrix result(m, other.n, -INF); rep(i, m) rep(j, other.n) rep(k, n) chmax(result.mat[i][j], mat[i][k] + other.mat[k][j]); return result; } Matrix pow(ll x) { assert(m == n); if(x == 0) return Matrix(m); Matrix result = pow(x / 2); result = result * result; return (x % 2 == 0 ? result : result * *this); } T dat() { assert(m == n); T result = 1; rep(i, m) { int pivot = -1; repu(j, i, m) if(mat[j][i] != 0) { pivot = j; break; } if(pivot == -1) return 0; if(pivot != i) { swap(mat[i], mat[pivot]); result *= -1; } result *= mat[i][i]; T inv = 1 / mat[i][i]; repu(j, i + 1, m) { T factor = mat[j][i] * inv; repu(k, i, n) mat[j][k] -= mat[i][k] * factor; } } return result; } }; int main() { cin.tie(0)->sync_with_stdio(0); int n; ll m; cin >> n >> m; vector t(n); cin >> t; vector> a(n, vector(n)); cin >> a; Matrix A(n, n), T(n, 1); rep(i, n) rep(j, n) A[i][j] = a[j][i]; rep(i, n) T[i][0] = t[i]; auto res = A.pow(m) * T; rep(i, n) cout << res[i][0] << " "; cout << endl; return 0; }