P1 = gets.to_i P2 = gets.to_i N = gets.to_i R = N.times.map { gets.to_i } checked = Hash.new(false) profit = 0 debt = 0 R.each do |r| if checked[r] debt += P1 + P2 else profit += P1 end checked[r] = true end puts debt