#include <bits/stdc++.h>

//#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pob pop_back
#define int long long
#define Shrek_Crush228 ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

using namespace std;

string alphabet = "abcdefghijklmnopqrstuvwxyz";
string num = "123456789";

const int N = 1e5 * 2;
const int imx = 1e9 + 1;
const int mod = 1e9 + 7;

/////////////////////////////////////////////////////////////
 
/////////////////////////////////////////////////////////////
//

/*
int fact[N];

int binpow( int a, int n )
{
	if( n == 0 ) return 1;
	
	if( n % 2 == 1 ) return ( binpow( a, n - 1 ) * a ) % mod;
	else 
	{
		int b = binpow( a, n / 2 ) % mod;
		return ( b * b ) % mod;
	}
}
int mod( int a, int b ) 
{
	return a & ( b - 1 );
}
int gcd( int a, int b )
{    
   if( b == 0 ) return a;
   else return gcd ( b, mod( a, b ) );
}
string to_bin( int bob )
{
	string ans = "";
	
	while( bob > 0 )
	{
		if( mod( bob, 2 ) == 0 ) ans += '0';
		else ans += '1';
		
		bob /= 2;
	}	
	reverse( ans.begin(), ans.end() );
	
	return ans;
}
int from_bin( string bob )
{
	int ans = 0;
	
	for( int i = 0; i < bob.size(); i ++ )
	{
		if( bob[i] == '1' ) ans = ans * 2 + 1;
		else ans *= 2;  
	}
	return ans;
}
*/
//////////////////////////////////////////////////////////////////////////////////////////////

void solve()
{	
	int n;
	cin >> n;
	
	int a[n + 5], b[n + 5];
	
	for( int i = 1; i <= n; i ++ )
	{
		cin >> a[i];
	}
	a[n + 1] = 1e18, b[n + 1] = 1e18;
	
	for( int i = 1; i <= n; i ++ )
	{
		cin >> b[i];
	}
	int ans = 0;
	
	for( int i = 1; i <= n; i ++ )
	{
		int x = i;
		
		for( int j = i + 1; j <= n + 1; j ++ )
		{
			if( a[j] > a[i] ) 
			{
				i = j - 1;
				break;
			}
		}	
		ans += min( b[i + 1], b[x] );	
	}
	cout << ans;
}
signed main() 
{
	//freopen("sum2.in", "r", stdin);
	//freopen("sum2.out", "w", stdout);
	    
    Shrek_Crush228
    
    int t;
	
	//cin >> t;
	t = 1;
	
	while( t -- )
	{
		solve();
	}
}
