#![allow(unused_imports)] #![allow(non_snake_case)] use std::cmp::*; use std::collections::*; use std::io::Write; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let v = read_vec::(); let (n, p) = (v[0] as usize, v[1]); let big_int = 1000_000_000 + 7; let mut a = vec![0; n + 1]; a[2] = 1; for i in 3..n + 1 { a[i] = p * a[i - 1] + a[i - 2]; a[i] %= big_int; } let mut sum = vec![0; n + 1]; for i in 1..n + 1 { sum[i] = a[i] + sum[i - 1]; sum[i] %= big_int; } let mut ans = 0; for i in 0..n + 1 { ans += (a[i] * sum[i]) % big_int; ans %= big_int; } println!("{}", ans); } fn read() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec() -> Vec { read::() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }