#include <iostream>
#include <vector>
#include<string>
#include<set>
#include <stack>
#include <iomanip>
#include <cmath>
#include<map>
#include <deque>
#include <queue>
using namespace std;
using ll = long long;
using ld = long double;

ll gcd(ll a, ll b) {
	while (b > 0) {
		if (a < 0) {
			a = (a % b + b) % b;
		}
		else {
			a %= b;
		}
		swap(a, b);
	}
	return 0;
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
signed main(){
	ll n;
	cin >> n;
	vector<ll>s(n);
	vector<ll>d(n);
	for (ll i = 0; i < n; ++i)
		cin >> s[i];
	for (ll i = 0; i < n; ++i)
		cin >> d[i];
	if (n == 1) {
		cout << d[0];
		return 0;
	}
	ll ans = 0;
	ll a, b;
	a = d[0];
	b = 0;
	for (ll i = 0; i < n-1; ++i) {
		if (s[i] < s[i + 1]) {
			ans += d[i+1];
		}
	}
	cout << ans + d[n - 1];
}
