#include using namespace std; using ll = long long; using pll = pair; #define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i) #define rep(i, n) drep(i, 0, n - 1) #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const ll MOD1000000007 = 1000000007; const ll MOD998244353 = 998244353; const ll MOD[3] = {999727999, 1070777777, 1000000007}; const ll LINF = 1LL << 60; const int IINF = (1 << 30) - 1; template struct Edge{ int to; T w; Edge(int to_, T w_=1){ to = to_; w=w_; } }; template using Tree = vector>>; template using Graph = vector>>; /* 容量&重み付きエッジ for Dinic */ template struct REdge{ int to; T cap; T cost; int rev; REdge(int to_, T cap_, T cost_=1){ to = to_; cap = cap_; cost = cost_; } REdge(int to_, T cap_, T cost_, int rev_){ to = to_; cap = cap_; cost = cost_; rev = rev_; } }; /* 残余グラフ for Dinic */ template using RGraph = vector>>; template struct mat{ vector> m; //行列m int nrow, ncol; //コンストラクタ : 第1引数⇒行数, 第2引数⇒列数, 第3引数⇒初期値 mat():m(vector>()){} mat(int h, int w):m(vector>(h, vector(w))){nrow=(int)m.size(); ncol=(int)m[0].size();} mat(int h, int w, T d):m(vector>(h, vector(w, d))){nrow=(int)m.size(); ncol=(int)m[0].size();} //添え字演算 vector operator[](const int i) const {return m[i];} //読み取り vector& operator[](const int i){return m[i];} //書き込み //行列&行列 演算 mat& operator=(const mat& a){return *a;} mat& operator+=(const mat& a){assert(ncol == a.ncol && nrow == a.nrow);rep(i,nrow)rep(j,ncol)m[i][j] += a[i][j]; return *this;} mat& operator-=(const mat& a){assert(ncol == a.ncol && nrow == a.nrow);rep(i,nrow)rep(j,ncol)m[i][j] -= a[i][j]; return *this;} mat& operator*=(const mat& a){assert(ncol == a.nrow);mat m2(nrow, a.ncol, 0);rep(i,nrow)rep(j,a.ncol)rep(k,ncol)m2[i][j] += m[i][k]*a[k][j];ncol = a.ncol;rep(i,nrow)m[i].resize(ncol);rep(i,nrow)rep(j,ncol)m[i][j] = m2[i][j]; return *this;} mat operator+(const mat& a) const { return mat(*this) += a;} mat operator-(const mat& a) const { return mat(*this) -= a;} mat operator*(const mat& a) const { return mat(*this) *= a;} bool operator==(const mat& a){assert(ncol == a.ncol && nrow == a.nrow);bool flg = true;rep(i,nrow)rep(j,ncol)if(m[i][j] != a[i][j])flg = false; return flg;} //行列&スカラ 演算 mat& operator+=(const T& a){rep(i,nrow)rep(j,ncol)m[i][j] += a;return *this;} mat& operator-=(const T& a){rep(i,nrow)rep(j,ncol)m[i][j] -= a;return *this;} mat& operator*=(const T& a){rep(i,nrow)rep(j,ncol)m[i][j] *= a;return *this;} mat& operator/=(const T& a){rep(i,nrow)rep(j,ncol)m[i][j] /= a;return *this;} mat operator+(const T& a) const { return mat(*this) += a;} mat operator-(const T& a) const { return mat(*this) -= a;} mat operator*(const T& a) const { return mat(*this) *= a;} mat operator/(const T& a) const { return mat(*this) /= a;} // 回転(degの数だけ時計回りに90度回転) mat& rot(int deg){ mat m2(ncol, nrow); if(deg == 1 || deg == 3){ if(deg == 1)rep(i,nrow)rep(j,ncol)m2[j][nrow -i -1] = m[i][j]; if(deg == 3)rep(i,nrow)rep(j,ncol)m2[ncol -j -1][i] = m[i][j]; swap(ncol,nrow); // 列数と行数を入れ替える m.resize(nrow);rep(i,nrow)m[i].resize(ncol); //リサイズ } if(deg == 2)rep(i,nrow)rep(j,ncol)m2[nrow -i -1][ncol -j -1] = m[i][j]; rep(i,nrow)rep(j,ncol)m[i][j] = m2[i][j]; return *this; } // 行列式 T det(){ mat sm(*this); assert(ncol==nrow); T ret = 1; for(int i=0; i pow(long long t){ mat ret(nrow, ncol); mat sm(nrow, ncol); for(int i=0; i 0){ if(t & 1) ret *= sm; sm *= sm; t >>= 1LL; } return ret; } // 標準出力 void show(){ rep(i,nrow)rep(j,ncol){ if(j != 0)cout << " "; cout << m[i][j]; if(j==ncol-1)cout << endl; } return ; } }; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); mat m(2, 2); rep(i, 2) rep(j, 2) cin >> m[i][j]; mat a = m.pow(3); rep(i, 2){ rep(j, 2){ cout << a[i][j] << " "; } cout << endl; } }