#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define fi first
#define se second
#define sz size
#define pb push_back

const int N = 1e5 + 10;

int main(){
    int n;
    cin >> n;
    int a[n+1], c[n+1];
    for(int i=1; i<=n; i++) cin >> a[i];
    for(int i=1; i<=n; i++) cin >> c[i];

    ll dp1[n+1], dp2[n+1];
    dp1[0]=0,dp2[0]=0;

    int l=0;
    for(int i=1; i<=n; i++) {
        if(i>1 && a[i]>a[i-1]) l++;
        else l=1;

        dp1[i] = dp1[i-l] + c[i];
    }

    l=0;
    dp2[n]=c[n];
    for(int i=n-1; i>=1; i--) {
        if(i<n && a[i]>a[i+1]) l++;
        else l=1;

        dp2[i] = dp2[i+l] + c[i];
    }
/*
    for(int i=1; i<=n; i++) {
        cout << dp1[i] << " " << dp2[i] << endl;
    }
*/
    ll ans=min(dp2[1], dp1[n]);
    for(int i=1; i<n; i++) {
        ans=min(ans,dp1[i]+dp2[i+1]);
    }
    cout << ans;

    return 0;
}
