#include #define M_PI 3.14159265358979323846 // pi using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector VI; typedef pair P; typedef tuple t3; typedef tuple t4; #define rep(a,n) for(ll a = 0;a < n;a++) #define repi(a,b,n) for(ll a = b;a < n;a++) #include using namespace std; const ll mod = 1e9 + 7; const ll INF = 1e15; int main() { ll p, k; cin >> p >> k; vector as; vector bs; as.reserve(k + 1); bs.reserve(k + 1); as.push_back(1); bs.push_back(0); rep(i, k) { auto a = (p + 1) * as.back() + 2 * (p - 1) * bs.back(); a %= mod; auto b = as.back() + 2 * (p - 1) * bs.back(); b %= mod; as.push_back(a); bs.push_back(b); } cout << as.back() << endl; return 0; }