#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
class Matrix{
public:
Matrix();
void Mult();
//friend void operator + (Matrix & a1 ,Matrix & a2);
void display();
int Count();
private:
int default[4][4];
int Afo[4][4];
int Re[4][4];
};
Matrix::Matrix(){
memset(default,0,sizeof(default));
memset(Afo,0,sizeof(Afo));
default[0][0] = 1 ,default[0][1] =2 ,default[1][2] = 1,default[2][0] =1 ,default[2][3] = 1,default[3][2]=1;
Afo[0][0] = 1 ,Afo[0][1] =2 ,Afo[1][2] = 1,Afo[2][0] =1 ,Afo[2][3] = 1,Afo[3][2]=1;
Re[0][0] = 1 ,Re[0][1] =2 ,Re[1][2] = 1,Re[2][0] =1 ,Re[2][3] = 1,Re[3][2]=1;
}
void Matrix::display(){
for(int i = 0 ; i < 4 ;++i){
for(int j = 0 ; j < 4 ; ++j){
cout<<Re[i][j]<<” “;
}
cout<<endl;
}
}
void Matrix::Mult(){
int result[4][4];
for(int i = 0 ; i < 4 ; ++i){
for(int j = 0 ; j < 4 ; ++j){
result[i][j] = Afo[i][0]*default[0][j] + Afo[i][1]*default[1][j] + Afo[i][2]*default[2][j] +Afo[i][3]*default[3][j];
}
}
for(int i = 0 ; i < 4 ; ++i)
for(int j = 0 ;j < 4 ; ++j) Afo[i][j] = result[i][j];
}
int Matrix::Count(){
int ans = 0 ;
for(int i = 0 ; i < 4 ; ++i)
for(int j = 0 ; j < 4 ; ++ j)
ans += Afo[i][j];
return ans ;
}
int main(){
Matrix a ;
int ans ;
for(int i = 1 ; i<= 3 ; ++i)
a.Mult();
a.display();
ans = a.Count();
cout<<ans<<endl;
system(“pause”);
return 0 ;
}