#pragma GCC optimize("O3", "unroll-loops") #include using namespace std; #define ll long long constexpr ll mod = 1000000007LL; int main(void){ int p, k; cin >> p >> k; vector> dp(k + 1, vector(2, 0LL)); dp[0][0] = 1; for (int i = 1; i <= k; ++i){ dp[i][0] = ((p - 1) * dp[i - 1][1] % mod * 2 + (p + 1) * dp[i - 1][0] % mod) % mod; dp[i][1] = (dp[i - 1][0] + 2 * (p - 1) % mod * dp[i - 1][1] % mod) % mod; } cout << dp[k][0] << endl; return 0; }