n = int(input())
h = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0

for i in range(n-1):
    if h[i] < h[i+1]:
        ans += c[i]
    else:
        a = 1
        flag = 0
        while h[i] > h[i + a]:
            a += 1
            if (i + a) > n - 1:
                flag = 1
                break
        if flag == 1:
            ans += c[i]
        else:
            ans += c[i]
            i += a
if n == 1:
    print(*c)
else:
    print(ans)