use std::io::Read; fn main() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let k: u64 = itr.next().unwrap().parse().unwrap(); let a: Vec = itr.map(|e| e.parse().unwrap()).collect(); let s = a.iter().sum::(); let mut ans = 0; for i in 0..n { ans = (ans * k + a[i]) % s; } println!("{}", ans); }