fn main() { let stdin = std::io::read_to_string(std::io::stdin().lock()).unwrap(); let mut stdin = stdin.split_ascii_whitespace(); let n: usize = stdin.next().unwrap().parse().unwrap(); let m: usize = stdin.next().unwrap().parse().unwrap(); let k: u32 = stdin.next().unwrap().parse().unwrap(); let op: char = stdin.next().unwrap().parse().unwrap(); let b: Vec = (0..m) .map(|_| stdin.next().unwrap().parse().unwrap()) .collect(); let a: Vec = (0..n) .map(|_| stdin.next().unwrap().parse().unwrap()) .collect(); use std::io::Write; std::io::stdout() .lock() .write_all(output(solve(k, op, a, b)).as_bytes()) .unwrap(); } fn solve(k: u32, op: char, mut a: Vec, mut b: Vec) -> u64 { a.sort_unstable(); b.sort_unstable(); let a = a; let b = b; let mut j = 0; a.len() as u64 * b.len() as u64 - match op { '+' => a .into_iter() .rev() .map(|a| { while j != b.len() && a + b[j] < k { j += 1; } j as u64 }) .sum::(), '*' => a .into_iter() .rev() .map(|a| { while j != b.len() && (a as u64 * b[j] as u64) < k as u64 { j += 1; } j as u64 }) .sum::(), _ => unreachable!(), } } fn output(ans: u64) -> String { ans.to_string() + "\n" }