#include <bits/stdc++.h>
#include <random>

#define i128 __int128
#define int long long

using namespace std;

random_device lal;
mt19937 rnd(lal());


const int inf = 1e18, mod = 998'244'353;


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> a(n), b(n), p(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    for (int &i: p) { cin >> i; }
    int ans = a[0];
    vector<vector<int> > dp(n, vector<int>(n, -inf));
    dp[0][0] = a[0];
    for (int i = 1; i < n; ++i) {
        int val =dp[i - 1][0];
        for (int t = 0; t <= i; ++t) {
            val = max(val, dp[i -1][t]);
            dp[i][t] = val + a[i] + t * b[i];
            ans = max(ans, dp[i][t]);
        }
    }
    cout<<ans;
}
