/*    ∫ ∫ ∫    ノヽ   (_  )  (_    ) (______ )  ヽ(´・ω・)ノ     |  /    UU */ #pragma region macro #include typedef long long int64; using namespace std; typedef vector vi; const int MOD = (int)1e9 + 7; const int64 INF = 1LL << 62; const int inf = 1<<30; const char bn = '\n'; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b ostream& operator<<(ostream& os, const vector &V){ int N = V.size(); REP(i,N){ os << V[i]; if (i!=N-1) os << " "; } os << "\n"; return os; } template ostream& operator<<(ostream& os, pair const&P){ os << "("; os << P.first; os << " , "; os << P.second; os << ")"; return os; } template ostream& operator<<(ostream& os, set &S){ auto it=S.begin(); while(it!=S.end()){ os << *it; os << " "; it++; } os << "\n"; return os; } template ostream& operator<<(ostream& os, deque &q){ for(auto it=q.begin();it ostream& operator<<(ostream& os, map const&M){ for(auto e:M){ os<> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)}; #pragma endregion //fixed< bit; for(b=b;b>0;b>>=1){ bit.push_back(b&1); } vector fac(bit.size()); fac[0] = a; int64 res = 1; for(int i=1;i= MOD) x -= MOD; return *this; } mint& operator-=(const mint a) { if ((x += MOD-a.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res+=a; } mint operator-(const mint a) const { mint res(*this); return res-=a; } mint operator*(const mint a) const { mint res(*this); return res*=a; } mint pow(int64 t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD-2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res/=a; } }; ostream& operator<<(ostream& os, mint a){ os << a.x; return os; } const mint two = 2; mint f(int64 K){ if(K==1) return 0; debug(mp(K,two.pow(K)-f(K-1))) return two.pow(K) - f(K-1); } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int64 P,K; cin >> P >> K; vector> DP(K+1,vector(2,0)); DP[0][true] = 1; REP(i,K){ DP[i+1][true] = DP[i][true] * (P+1) + DP[i][false] * 2; DP[i+1][false] = DP[i][true] * (P-1) + DP[i][false] * (2*P - 2); } auto ans = DP.back()[true]; cout << ans << endl; }