#include using namespace std; #include using namespace atcoder; using ll = long long; #define rep(i, n) for (ll i = 0; i < (ll) (n); i++) using mint =modint1000000007; using vm = vector; int main() { ll P,K; cin>>P>>K; vm D(K+1,0),E(K+1,0); D[0]=1; rep(i,K){ E[i+1]=(D[i]+2*E[i])*(P-1); D[i+1]=2*E[i]+D[i]*(P+1); } cout<