const MOD: usize = 1e9 as usize + 7; fn main() { let mut pk = String::new(); std::io::stdin().read_line(&mut pk).ok(); let pk: Vec = pk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let p = pk[0]; let k = pk[1]; let mut dp = vec![vec![0usize; 2]; k+1]; dp[0][0] = 1; for i in 0..k { dp[i+1][0] += dp[i][0]; dp[i+1][0] += dp[i][1]; dp[i+1][0] += dp[i][0] * p % MOD; dp[i+1][0] += dp[i][1]; dp[i+1][0] %= MOD; dp[i+1][1] += dp[i][0] * (p-1) % MOD; dp[i+1][1] += dp[i][1] * (p-1) % MOD; dp[i+1][1] += dp[i][1] * (p-1) % MOD; dp[i+1][1] %= MOD; } println!("{}", dp[k][0]); }