# coding: utf-8



from itertools import combinations, chain



N = int(eval(input()))

values = list(map(int, input().split()))

costs = list(map(int, input().split()))



sales = [v - c for v, c in zip(values, costs)]



print((max(chain.from_iterable(list(map(sum, combinations(sales, i))) for i in range(0, N+1)))))

n = int(input().strip())

values = list(map(int, input().split()))

costs = list(map(int, input().split()))

 

sales = [v - c for v, c in zip(values, costs) if v > c]

 

print((sum(sales)))
# coding: utf-8
from itertools import combinations, chain

N = int(eval(input()))
values = list(map(int, input().split()))
costs = list(map(int, input().split()))
sales = [v - c for v, c in zip(values, costs)]
print(
    (
        max(
            chain.from_iterable(
                list(map(sum, combinations(sales, i))) for i in range(0, N + 1)
            )
        )
    )
)

n = int(input().strip())
values = list(map(int, input().split()))
costs = list(map(int, input().split()))
sales = [v - c for v, c in zip(values, costs) if v > c]
print((sum(sales)))

-# coding: utf-8 -from itertools import combinations, chain - -N = int(eval(input())) +n = int(input().strip()) -sales = [v - c for v, c in zip(values, costs)] -print( -    ( -        max( -            chain.from_iterable( -                list(map(sum, combinations(sales, i))) for i in range(0, N + 1) -            ) -        ) -    ) -) +sales = [v - c for v, c in zip(values, costs) if v > c] +print((sum(sales)))