class Yukicoder DRY = 0 WET = 1 MOIST = 2 def initialize n = gets.to_i a = gets.chomp.split.map(&:to_i).sort dry = Array.new(n, false) wet = Array.new(n, false) moist = Array.new(n, false) answer = Array.new(3, 0) minus = a.select{|i| i < 0}.reverse plus = a.select{|i| i >= 0} mcnt = 0 while minus.any? && plus.any? val = minus.shift if plus[0] + val < 0 answer[DRY] += 1 plus.shift else mcnt += 1 end end answer[DRY] += (mcnt+minus.size)/2 minus = a.select{|i| i < 0}.reverse plus = a.select{|i| i >= 0} trush = [] while minus.any? && plus.any? val = plus.shift if minus[0] + val > 0 answer[WET] += 1 minus.shift else trush << val end end trush += plus if trush.count(0) > trush.size/2 answer[WET] += trush.count{|i| i > 0} else answer[WET] += (trush.size/2) end checkList = Hash.new(0) a.each do |num| if num >= 0 && checkList[-num] > 0 answer[MOIST] += 1 checkList[-num] -= 1 elsif num <= 0 checkList[num] += 1 end end puts answer.join(' ') end end Yukicoder.new