Mat power(Mat M,int P){
Mat tot(1);
while (P){
if (P&1) tot=tot*M;
P>>=1,M=M*M;
}
return tot;
}
Mat count(Mat M,int P){
Mat M0,E(1),M1=E;
while (P){
if (P&1) M0=M0+M1*power(M,P);
P>>=1;
M1=M1*(E+power(M,P));
}
return M0;
}