//#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <random>
#include <chrono>
/*
Bismillah hir rahman nir raheem
*/
using namespace std;
#define ll long long
#define ull unsigned long long 
#define pb(e) push_back(e)
#define all(v) v.begin(), v.end()
void gen(int &s, int n, int m, vector<int>& d)
{
    s += n * m;
    if ( n <= 1 || m <= 1)
    {
        s -= n* m;
        s += d[n * m];
        return;
    }
    else
    {
        int t = n / 2;
        gen(s, m, t, d);
        gen(s, m, n - t, d);
    }
}
void solve()
{
    int n;
    cin >> n;
    vector<int> a(n), v(n);
    for ( int i = 0; i < n; i++ )
    {
        cin >> a[i];
    }
    for ( int i = 0; i < n; i++ )
    {
        cin >> v[i];
    }
    int l = 0, r = n - 1;
    ll ans = 0;
    while(r >= l)
    {
        if ( a[r] > a[r - 1] )
        {
            ans += v[r];
        }
        if ( a[l] >a[l + 1] )
        {
            ans += v[l + 1];
        }
        l++;
        r--;
    }
    cout << ans;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1; 
    while (t--)
    {
        solve();
        cout << endl;
    }
    return 0;
}