use std::cmp::Reverse; fn main() { let mut nmx = String::new(); std::io::stdin().read_line(&mut nmx).ok(); let nmx: Vec = nmx.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nmx[0]; let m = nmx[1]; let x = nmx[2]; let mut problems = (0..n).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); (temp[0], temp[1]-1) }) .collect::>(); let mut k = String::new(); std::io::stdin().read_line(&mut k).ok(); let k: usize = k.trim().parse().unwrap(); let mut c = String::new(); std::io::stdin().read_line(&mut c).ok(); let c: Vec = c.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut ccnt = vec![0usize; n+1]; for &v in c.iter() { ccnt[v] += 1; } problems.sort_by_key(|&(s, _)| Reverse(s)); let mut scores = Vec::with_capacity(n); let mut used = vec![false; m]; for &(score, pat) in problems.iter() { scores.push(score + if !used[pat] { x } else { 0 }); used[pat] = true; } scores.sort_by_key(|&v| Reverse(v)); let mut summary = 0usize; let mut result = 0usize; for i in 0..n { summary += scores[i]; result += ccnt[i+1] * summary; } println!("{}", result); }