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 { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } fn main() { let input:Vec = read_vec(); let n = input[0]; let _m = input[1]; let k = input[2]; let mut op_with_b:Vec = read_vec(); let op_str = op_with_b.remove(0); let b_s:Vec = op_with_b.iter().map(|v| v.parse().unwrap()).collect(); let a_s:Vec = (0..n).map(|_i| { read() }).collect(); let mut ans = 0; let mut sum_a = 0; for a in a_s { sum_a = (sum_a + a) % k; } if op_str == "+" { for b in b_s { ans = (ans + n * b + sum_a) % k; } } else { for b in b_s { ans = (ans + b * sum_a) % k; } } println!("{}", ans % k); }