loss = gets.chomp.to_i + gets.chomp.to_i rooms = [] gets.chomp.to_i.times { rooms << gets.chomp } n = 0 rooms.group_by { |r| r }.reject { |k,v| v.one? }.each { |k,v| n += v.count - 1 } puts n > 0 ? loss * n : 0