n = int(input())
a = [int(_) for _ in input().split()]
w = [int(_) for _ in input().split()]

if sum(a) == n or sum(a) == 0:
    print(0)
    quit()

lia = []
lib = []
for i in range(n):
    if a[i] == 0:
        lia.append(w[i])
    else:
        lib.append(w[i])

print(min(lia)+min(lib))
