p1 = gets.to_i # 宿泊料金 p2 = gets.to_i # 振替先宿泊料金 n = gets.to_i # 予約件数 sum = 0 #料金合計 roomNumber = Array.new count = Hash.new(0) n.times do |i| roomNumber[i] = gets.chomp end roomNumber.each do |elem| count[elem] += 1 end count.each do |k, v| if v > 1 sum += (v - 1) end end sum = (p1 + p2) * sum puts sum