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

#pragma GCC optimize("O3,unroll-loops")

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define debug(x) cout << "\n!debug " << (#x) << ": " << x << "\n";
#define int long long
#define vec vector

struct pers {
    int a, b;
};

void talantless(int n, vector<pers> &d, vector<int> &p) {
    vec<vec<int>> dp(n, vec<int>(n, -2e18)), pref_max(n, vec<int>(n, -2e18));
    dp[0][0] = d[0].a;
    pref_max[0][0] = d[0].a;
    for (int i = 0; i < n; ++i) {
        pref_max[0][i] = d[0].a;
    }
    for (int i = 1; i < n; ++i) {
        for (int take = 0; take <= i; ++take) {
            // dp[i][take]
            int boost = d[i].a + (d[i].b * take);
            int best_pred = pref_max[i-1][take];

            // for (int time = 0; time <= take; ++time) {
            //     best_pred = max(dp[i-1][time], best_pred);
            // }

            dp[i][take] = best_pred + boost;
        }

        pref_max[i][0] = dp[i][0];
        for (int j = 1; j <= i; ++j) {
            pref_max[i][j] = max(dp[i][j], pref_max[i][j-1]);
        }
    }

    

    int best = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            best = max(dp[i][j], best);
        }
    }

    cout << best << "\n";
}

signed main() {
    // ios::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<pers> d(n);
    for (int i = 0; i < n; ++i) {
        cin >> d[i].a >> d[i].b;
    }
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    talantless(n, d, p);
}