#ifdef LOCAL
#define GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

constexpr ll mod = 998244353;

mt19937_64 rnd(28);

void solve() {
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    vector<ll> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    vector<ll> sufm(n + 1), prefm(n);
    sufm[n] = n;
    prefm[0] = max(0ll, p[0]);
    for (int i = 1; i < n; ++i) {
        prefm[i] = prefm[i - 1];
        if (p[i] != -1) {
            prefm[i] = max(prefm[i], p[i]);
        }
    }
    for (int i = n - 1; i >= 0; --i) {
        sufm[i] = sufm[i + 1];
        if (p[i] != -1) {
            sufm[i] = min(sufm[i], p[i]);
        }
    }
    ll cur = 0, ans = -1e18;
    vector<vector<ll>> dp(n, vector<ll>(n + 1, -1e18));
    dp[0][0] = 0;
    for (int i = 1; i <= sufm[0]; ++i) {
        dp[0][i] = dp[0][i - 1] + a[i - 1];
    }
    for (int i = 0; i < prefm[0]; ++i) {
        dp[0][i] = -1e18;
    }
    for (ll i = 1; i < n; ++i) {
        for (int j = max(i * 1ll, prefm[i]); j <= sufm[i]; ++j) {
            for (int k = max(i * 1ll, prefm[i - 1]); k <= min(j * 1ll, sufm[i - 1]); ++k) {
                ll d = 0;
                for (int m = k; m < j; ++m) {
                    d += a[m] + b[m] * i;
                }
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + d);
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = prefm[i]; j <= sufm[i]; ++j) {
            //cout << i << ' ' << j << ' ' << dp[i][j] << '\n';
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
        cout << endl;
    }
}