#include <bits/stdc++.h> using namespace std; #define modulo 1000000007 #define mod(mod_x) ((((long long)mod_x+modulo))%modulo) #define Inf 1000000 int main(){ int P,K; cin>>P>>K; vector<vector<int>> dp(K+1,vector<int>(2,0)); dp[0][0] = 1; for(int i=0;i<K;i++){ dp[i+1][0] = mod(dp[i+1][0] + mod(dp[i][0]*(P+1))); dp[i+1][1] = mod(dp[i+1][1] + mod(dp[i][0]*(P-1))); dp[i+1][0] = mod(dp[i+1][0] + mod(dp[i][1]*2)); dp[i+1][1] = mod(dp[i+1][1] + mod(dp[i][1]*mod(2*P-2))); } cout<<dp.back()[0]<<endl; return 0; }