根据年份改为3x3的矩阵递推。

#include <iostream>
#include <vector>
using namespace std;
const long long MOD=1000000007;
vector<vector<long long>> mult(vector<vector<long long>>&x1,vector<vector<long long>>&x2){
    vector<vector<long long>> xx{{0,0,0},{0,0,0},{0,0,0}};
    for(int i=0;i<3;++i)
        for(int j=0;j<3;++j)
            xx[i][j]=(x1[i][0]*x2[0][j]+x1[i][1]*x2[1][j]+x1[i][2]*x2[2][j])%MOD;
    return xx;
}
int pown(long long n){
    vector<vector<long long>> res{{1,0,0},{0,1,0},{0,0,1}};
    vector<vector<long long>> x{{1,0,1},{1,0,0},{0,1,0}};
    while(n){
        if(n&1) res=mult(res,x);
        x=mult(x,x);
        n>>=1;
    }
    return (3*res[0][0]+2*res[0][1]+res[0][2])%MOD;
}
int main(){
    int res;
    long long n;
    cin>>n;
    if(n<4){
        cout<<n;
        return 0;
    }
    res=pown(n-3);
    cout<<res<<endl;
}