def f(a, b) _party = a.map.with_index{|v,i| [v, 0, i]} b.size.times.map{ party = _party.dup b.each{|enemy| lv, cnt, idx = party.min party[idx] = [enemy/2 + lv, cnt + 1, idx] } b.rotate! party.max_by{|lv,cnt,idx| cnt}[1] }.min end N = gets.to_i A = gets.split.take(N).map(&:to_i) B = gets.split.take(N).map(&:to_i) p f(A, B)