use std::io::Read; fn main() { const DIVIDER: u128 = 1_000_000_007; let mut np = String::new(); std::io::stdin().read_to_string(&mut np).ok(); let np: Vec = np.trim().split('\n').next().unwrap().trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = np[0]; let p = np[1]; let mut fibs = vec![]; fibs.push(0); fibs.push(1); for i in 2..n { fibs.push((fibs[(i as usize)-2] + p * fibs[(i as usize)-1]) % DIVIDER); } let summary: u128 = fibs.iter().sum(); let result: u128 = (summary * summary + fibs.iter().map(|i| (i * i) as u128).sum::()) / 2 % DIVIDER; if n == 1 { println!("0"); } else { println!("{}", result); } }