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 k: u128 = nmk[2]; let opb: Vec<&str> = all_data.next().unwrap().split_whitespace().collect(); let b: Vec = opb.iter().skip(1).map(|s| s.parse().unwrap()).collect(); let op: &str = opb[0]; let a: Vec = all_data.take(n as usize).map(|s| s.parse().unwrap()).collect(); let mut result: u128 = 0; for i in a.iter() { result += b.iter() .map(|j| match op { "+" => i + j, "*" => i * j, _ => 0 }) .sum::() ; result %= k; } println!("{}", result); }