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:
        flag = 0
        j = i + 1
        while h[i] > h[j]:
            j += 1
            if j > n - 1:
                flag = 1
                break
        if flag == 1:
            ans += c[i]
            flag = 0
            print(ans)
            exit()
        else:
            ans += c[i]
            i = j
if n == 1:
    print(*c)
else:
    i = n - 1
    if h[i] > h[i-1]:
        ans += c[i]

    print(ans)