fn main() { let v = read_vec::(); let (n, k) = (v[0], v[1] as i64); let a = read_vec::(); let sum_a = a.iter().sum::(); let mut ans = 0; for anum in a { ans *= k; ans += anum; ans %= sum_a; } 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() }