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 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 mut ans = 0; if op_str == "+" { for _i in 0..input[0] { let a:i64 = read(); for j in 0..input[1] { ans += a + b_s[j]; } } } else { for _i in 0..input[0] { let a:i64 = read(); for j in 0..input[1] { ans += a * b_s[j]; } } } println!("{}", ans % input[2] as i64); }