gets.to_i w_list = gets.to_s.split(" ").map(&:to_i).sort{|a, b| b <=> a}.uniq.map{|n| ["W", n] } gets.to_i b_list = gets.to_s.split(" ").map(&:to_i).sort{|a, b| b <=> a}.uniq.map{|n| ["B", n] } result_list = (w_list + b_list) (w_list + b_list).sort{|a, b| b[1] <=> a[1]}.each_cons(2){|n1, n2| result_list.push ["WB",n1[1]] if n1[1] == n2[1]} result_list.sort!{|a, b| b[0] <=> a[0] }.sort!{|a, b| b[1] <=> a[1]}.uniq!{|n| n[1]} #p result_list count = 1 result_list.each_cons(2){|n1, n2|count += 1 if !(n1[0].eql? n2[0]) || (n1[0].eql?("WB") && n2[0].eql?("WB"))} if result_list.length != 1 p count