推一下矩阵就好了:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define db double
#define sg string
#define ll long long
#define rel(i,x,y) for(ll i=(x);i<(y);i++)
#define rep(i,x,y) for(ll i=(x);i<=(y);i++)
#define red(i,x,y) for(ll i=(x);i>=(y);i--)
#define res(i,x) for(ll i=head[x];i;i=nxt[i])
using namespace std;
const ll N=11;
const ll Inf=1e18;
const ll Mod=1e9+7;
const db Eps=1e-10;
ll n,m;
typedef ll mat[N][N];
mat ans={
1,0,0,0,0,0,0,0,0,0,0,
0,1,0,0,0,0,0,0,0,0,0,
0,0,1,0,0,0,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,0,0,
0,0,0,0,1,0,0,0,0,0,0,
0,0,0,0,0,1,0,0,0,0,0,
0,0,0,0,0,0,1,0,0,0,0,
0,0,0,0,0,0,0,1,0,0,0,
0,0,0,0,0,0,0,0,1,0,0,
0,0,0,0,0,0,0,0,0,1,0,
0,0,0,0,0,0,0,0,0,0,1
};
mat ret={
0,1,1,1,1,1,1,1,1,1,0,
1,0,0,0,0,0,0,0,0,0,0,
0,1,0,0,0,0,0,0,0,0,0,
0,0,1,0,0,0,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,0,0,
0,0,0,0,1,0,0,0,0,0,0,
0,0,0,0,0,1,0,0,0,0,0,
0,0,0,0,0,0,1,0,0,0,0,
0,0,0,0,0,0,0,1,0,0,0,
0,0,0,0,0,0,0,0,1,0,0,
0,0,0,0,0,0,0,0,0,1,0
};
inline ll read() {
ll x=0;char ch=getchar();bool f=0;
while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return f?-x:x;
}
inline ll add(ll x,ll y) {
return x+y>=Mod?x+y-Mod:x+y;
}
inline ll mul(ll x,ll y) {
return x*y%Mod;
}
void calc(mat x,mat y) {
mat z;
rep(i,0,10) rep(j,0,10) {
z[i][j]=0;
rep(k,0,10) z[i][j]=add(z[i][j],mul(x[i][k],y[k][j]));
}
rep(i,0,10) rep(j,0,10) x[i][j]=z[i][j];
}
void solve() {
n=read();n--;
while(n) {
if(n&1) calc(ans,ret);
n>>=1;calc(ret,ret);
}
ll tot=0;
rep(i,0,9) tot=add(tot,ans[i][1]);
printf("%lld\n",tot);
}
void File() {
freopen("rabbit.in","r",stdin);
freopen("rabbit.out","w",stdout);
}
int main() {
// File();
solve();
return 0;
}