#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll INF=1LL<<60; typedef pair P; typedef pair PP; const ll MOD=1e9+7; ll mod_pow(ll x,ll y,ll mod){ ll res=1; while(y>0){ if(y&1){ res*=x; res%=mod; } x*=x; x%=mod; y/=2; } return res; } int main(){ ll N,K; cin>>N>>K; ll ans=(mod_pow(N,K,MOD) - mod_pow(N-1,K,MOD)+MOD)%MOD; ans*=N; ans%=MOD; cout<