use std::io::Read; fn main() { let mut all_data = String::new(); std::io::stdin().read_to_string(&mut all_data).ok(); let mut all_data = all_data.trim().split('\n').map(|s| s.trim()); let nmk: Vec = all_data.next().unwrap().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n: u128 = nmk[0]; let m: u128 = nmk[1]; let k: u128 = nmk[2]; let opb: Vec<&str> = all_data.next().unwrap().split_whitespace().collect(); let b_sum: u128 = opb.iter().skip(1).map(|s| s.parse::().unwrap()).sum(); let op: &str = opb[0]; let a_sum: u128 = all_data.take(n as usize).map(|s| s.parse::().unwrap()).sum(); let result: u128 = match op { "+" => a_sum * m + b_sum * n, "*" => a_sum * b_sum, _ => 0 }; println!("{}", result % k); }