n = gets.to_i
v_arr = gets.split.map(&:to_i)
c_arr = gets.split.map(&:to_i)
res = []
(0..n).each do |i|
  res_arr = v_arr.combination(i).zip(c_arr.combination(i))
  res_arr.each do |x, y|
    res << x.inject(:+) - y.inject(:+) if !x.empty? && !y.empty?
  end
end
ans = res.max >= 1 ? res.max : 0
puts ans