use std::io::Read; fn main() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let s: Vec<_> = s.split_whitespace().collect(); let n: u128 = s[0].parse().unwrap(); let m: usize = s[1].parse().unwrap(); let k: u128 = s[2].parse().unwrap(); let o = s[3]; let b = s[4..4 + m] .iter() .flat_map(|s| s.parse::()) .sum::(); let a = s[4 + m..] .iter() .flat_map(|s| s.parse::()) .sum::(); println!( "{}", if o == "+" { (a * m as u128 + b * n) % k } else { a * b % k } ) }