
N = int(input())
a = [int(i) for i in input().split()]
w = [int(i) for i in input().split()]

rightMin = 1001
leftMin = 1001

for i in range(N):
    if a[i] == 0:
        rightMin = min(rightMin, w[i])
    else:
        leftMin = min(leftMin, w[i])

if rightMin == 1001 or leftMin == 1001:
    print(0)
else:
    print(rightMin + leftMin)
    
    
