gets array = gets.split.map(&:to_i).zip(gets.split.map(&:to_i)) hash = Hash.new(0) array.each do |val| hash[val[1]] += val[0] end puts hash.values.max == hash[0] ? 'YES' : 'NO'