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

using ll = long long;

int main() {
    ll n;
    cin >> n;

    vector<ll> a(n), b(n), p(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (ll i = 0; i < n; i++) {
        cin >> b[i];
    }
    for (ll i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
    }


    vector<ll> mn(n, 0), mx(n, n);
    for (ll i = 0; i < n; i++) {
        if (p[i] != -2) {
            mx[p[i]] = i + 1;
            if (p[i] + 1 < n)
                mn[p[i] + 1] = i + 2;
        }
    }
    vector<ll> t(n, -1);
    for (ll i = 0; i < n; i++) {
        ll c_mn = mn[i];
        if (i > 0)
            c_mn = max(c_mn, t[i - 1]);
        ll c_mx = mx[i];
        c_mx = min(c_mx, i + 1);
        t[i] = c_mx;
    }

    ll ans = 0, cur = 0;
    for (ll i = 0; i < n; i++) {
        cur += a[i] + b[i] * t[i];
        ans = max(ans, cur);
    }

    cout << ans << '\n';
}