n = gets.to_s.to_i a = gets.to_s.split.map(&.to_i) b = gets.to_s.split.map(&.to_i) temp = a.map { |val| {val, 0} } ans = 10**9 n.times do |i| heap = temp.dup ma = 0 n.times do |j| # Get and remove the smallest element min_index = heap.index(heap.min_by { |pair| pair[0] }).not_nil! t, u = heap.delete_at(min_index) new_val = t + b[(i + j) % n] // 2 new_pair = {new_val, u + 1} heap << new_pair ma = Math.max(ma, u + 1) end ans = Math.min(ans, ma) end puts ans