#include <bits/stdc++.h>

using ll = long long;

const ll INF = 2e18;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    vector<int> p(n), l(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        for (int j = 0; j < p[i]; j++) {
            l[j] = max(l[j], i + 1);
        }
    }
    vector<vector<ll>> dp(n, vector<ll>(n)), pr(n, vector<ll>(n));
    dp[0][0] = a[0];
    pr[0][0] = a[0];
    for (int i = 1; i < n; i++) {
        for (int t = l[i]; t <= i; t++) {
            dp[i][t] = a[i] + b[i] * t + pr[i - 1][t];
        }
        pr[i][0] = dp[i][0];
        for (int t = max(1, l[i]); t <= i; t++) {
            pr[i][t] = max(pr[i][t - 1], dp[i][t]);
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    bool MULTITEST = 0;
    #ifdef egg
        MULTITEST = 1;
        freopen("test.txt", "r", stdin);
    #endif
    if (MULTITEST) {
        cin >> t;
    }
    while (t--) {
        solve();
    }
    return 0;
}
