#include #include #define int long long using namespace std; constexpr int mod=1e9+7; int pow(int x,int n){ int res=1; while(n){ if(n&1) (res*=x)%=mod; (x*=x)%=mod; n>>=1; } return res; } int inv(int n){ return pow(n,mod-2); } int fact[100001]; int mod_fact(int n){ if(fact[n]!=0) return fact[n]; if(n==0) return fact[n]=1; return fact[n]=n*mod_fact(n-1)%mod; } int comb(int n,int k){ return mod_fact(n)*inv(mod_fact(k)*mod_fact(n-k)%mod)%mod; } typedef vectorvec; typedef vectormat; mat mul(mat a,mat b){ mat c(a.size(),vec(b[0].size())); for(int i=0;i>=1; } return b; } signed main(){ int n,m; cin>>n>>m; int ans=m*(m-1)%mod; if(m&1) ans=mod-ans; for(int i=3;i<=m;i+=1){ mat a(1,vec(2)),b(2,vec(2)),c(2,vec(1)); a[0][0]=1,a[0][1]=1; b[0][0]=(i*i*i-i*i*6+i*14-13)%mod,b[0][1]=(i*i*i-i*i*6+i*13-10)%mod,b[1][0]=(i*i-i*4+5)%mod,b[1][1]=(i*i-i*3+3)%mod; c[0][0]=(i*i*i-i*i*3+i*2)%mod,c[1][0]=(i*i-i)%mod; int tmp=mul(mul(a,pow_mat(b,n-1)),c)[0][0]; (tmp*=comb(m,i))%=mod; if((m-i)&1) tmp=mod-tmp; (ans+=tmp)%=mod; } cout<