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(|&(v, _)| v); let mut used = vec![false; m]; let mut scores = vec![0usize; n]; for i in (0..n).rev() { let (a, b) = pairs[i]; if !used[b] { scores[i] += x; } scores[i] += a; used[b] = true; } scores.sort(); scores.reverse(); let mut result = 0usize; let mut summary = 0usize; for i in 1..=n { summary += scores[i-1]; result += summary * ccnts[i]; } println!("{}", result); }