#include #include using namespace std; using ll = long long; constexpr ll MOD = 1e9 + 7; int main() { ll p, k; cin >> p >> k; vector a(k + 1), b(k + 1); a[0] = 1, b[0] = 0; for (int i = 0; i < k; i++) { a[i + 1] = ((p + 1) * a[i] + 2 * (p - 1) * b[i]) % MOD; b[i + 1] = (a[i] + 2 * (p - 1) * b[i]) % MOD; } cout << a[k] << endl; return 0; }