class Yukicoder def initialize n = gets.chomp.to_i w = gets.chomp.split(' ').map(&:to_i).sort n = gets.chomp.to_i b = gets.chomp.split(' ').map(&:to_i).sort dw = w.dup db = b.dup listA = [] listB = [] number = 0 while w.any? || b.any? if listA.size.even? if w.first.to_i > number number = w.shift listA << number elsif w.empty? break; else w.shift end else if b.first.to_i > number number = b.shift listA << number elsif b.empty? break else b.shift end end end number = 0 while dw.any? || db.any? if listB.size.odd? if dw.first.to_i > number number = dw.shift listB << number elsif dw.empty? break; else dw.shift end else if db.first.to_i > number number = db.shift listB << number elsif db.empty? break else db.shift end end end puts [listA.size, listB.size].max end end Yukicoder.new