#include #include #include #include #include #include #include using namespace std; using ll = long long; constexpr int P = 1000000007; int main() { int p, k; cin >> p >> k; ll s[2] = { 1, 0 }; for (int i = 0; i < k; i++) { ll t[2]; t[0] = s[0] * (1 + p) + s[1] * 2; t[1] = s[0] * (p - 1) + s[1] * (p - 1) * 2; for (int h = 0; h < 2; h++) s[h] = t[h] % P; } cout << s[0] << endl; return 0; }