#include using namespace std; using ll=long long; const ll mod=1000000007; ll mpow(ll n,ll k){ ll ret=1; while(k){ if(k&1)ret*=n; n*=n; k/=2; ret%=mod;n%=mod; } return ret; } int main(){ ll n,k; cin>>n>>k; k%=mod; cout<<(mpow(k*(k+1)%mod*500000004%mod+k,n)-mpow(k*(k+1)%mod*500000004%mod,n)+mod*10)%mod<