fn main() { let p1: u32 = input_line()[0]; let p2: u32 = input_line()[0]; let n: usize = input_line()[0]; let mut rv: Vec = Vec::new(); for _i in 0..n { rv.push(input_line::()[0]); } rv.sort(); let mut cost = 0; for i in 1..n { if rv[i] == rv[i - 1] { cost += p1 + p2; } } println!("{}", cost); } fn input_line() -> Vec { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }