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 pairs = (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 ccnts = vec![0usize; n+1]; for &v in c.iter() { ccnts[v] += 1; } pairs.sort_by_key(|&(a, _)| Reverse(a)); let mut checked = vec![false; m]; let mut scores = Vec::with_capacity(n); for &(a, b) in pairs.iter() { if !checked[b] { checked[b] = true; scores.push(a+x); } else { scores.push(a); } } scores.sort(); scores.reverse(); let mut current = 0usize; let mut result = 0usize; for i in 0..n { current += scores[i]; result += current * ccnts[i+1]; } println!("{}", result); }