struct Martix
{
ll mp[5][5];
ll r,c;
};
Martix mul(Martix a,Martix b)
{
Martix c;
c.r=a.r;
c.c=b.c;
for(int i=0;i<a.r;i++)
{
for(int j=0;j<b.c;j++)
{
c.mp[i][j]=0;
for(int k=0;k<a.c;k++)
{
c.mp[i][j]=(a.mp[i][k]*b.mp[k][j]+c.mp[i][j]+mod)%mod;
c.mp[i][j]%=mod;
}
}
}
return c;
}
Martix ans;
Martix a;// 系数矩阵
void init()
{
memset(ans.mp,0,sizeof(ans.mp));
ans.r=2;
ans.c=1;
ans.mp[0][0]=36;
ans.mp[1][0]=11;
ans.mp[2][0]=5;
ans.mp[3][0]=1;
a.r=a.c=4;
memset(a.mp,0,sizeof(a.mp));
a.mp[0][0]=1;
a.mp[0][1]=5;
a.mp[0][2]=1;
a.mp[0][3]=-1;
a.mp[1][0]=a.mp[2][1]=a.mp[3][2]=1;
}
Martix pow(Martix x,ll k)
{
Martix temp;
temp.r=temp.c=x.r;
memset(temp.mp,0,sizeof(temp.mp));
for(int i=0;i<x.r;i++) // 单位矩阵
{
for(int j=0;j<x.c;j++) if(i==j) temp.mp[i][j]=1;
}
while(k)
{
if(k&1) temp=mul(x,temp);
k/=2;
x=mul(x,x);
}
return temp;
}
int main()
{
a=pow(a,n-4);// 系数矩阵先快速幂乘一下
ans=mul(a,ans);// 最后和初始矩阵乘一下
return 0;
}