n = gets.to_i
vs = gets.split.map(&:to_i)
cs = gets.split.map(&:to_i)

len = vs.length
array = []
(0..("1" * len).to_i(2)).each do |i|
  array << i.to_s(2).rjust(len, "0")
end

ans = 0

array.each do |a|
  v = 0
  cost = 0
  a.chars.each.with_index do |c,i|
    if c == "1"
      v += vs[i]
      cost += cs[i]
    end
  end
  next if v.nil?
  ans = [ans, v - cost].max
end

puts ans

# tmp = 1
# ans = [ans, tmp].min
