n = gets.to_i
value = gets.split(" ").map(&:to_i)
cost = gets.split(" ").map(&:to_i)

v_c = []
for i in 0..n-1
  array = [value[i], cost[i]]
  v_c << array
end

ans = []
for i in 1..2 ** n
  bit = i
  combi = []
  v_c.each_with_index do |v, j|
    if bit[j] == 1
      combi << v
    end
  end
  if !combi.empty?
    x = 0 ; y = 0
    combi.each do |com|
      x += com[0] ; y += com[1]
    end
    ans << x - y
  elsif combi.empty?
    ans << 0
  end
end

puts ans.max