#include <iostream>
#include <vector>
#include <algorithm>
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,lzcnt,popcnt,bmi,bmi2")
#define int long long
using namespace std;
const int INF = 2000000000000000000;

const int maxn = 5002;
int tree[2][4 * maxn];
void sett(int ind, int v, int l, int r, int ql, int qr, int x) {
    if (ql > r || l > qr) return;
    if (ql <= l && r <= qr) {tree[ind][v] = max(tree[ind][v], x); return;}
    int m = (l + r) / 2;
    sett(ind, 2 * v + 1, l, m, ql, qr, x);
    sett(ind, 2 * v + 2, m + 1, r, ql, qr, x);
}

int gett(int ind, int v, int l, int r, int x) {
    if (l > x || r < x) return -INF;
    if (l == r) return tree[ind][v];
    int m = (l + r) / 2;
    return max(tree[ind][v], max(gett(ind, 2 * v + 1, l, m, x), gett(ind, 2 * v + 2, m + 1, r, x)));
}


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 4 * maxn; j++) tree[i][j] = -INF;
    }

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

    vector<vector<int>> dp(n, vector<int>(n, -INF));
    int ans = max(0ll, a[0]);
    // sett(0, 0, 0, n - 1, 0, n - 1, a[0]);
    for (int i = 0; i < n; i++) dp[0][i] = a[0];
    // cout << gett(0, 0, 0, n - 1, 1) << endl;
    int pred = 0;

    for (int i = 1; i < n; i++) {
        // for (int j = 0; j < n; j++) tree[1 - pred][j] = -INF;
        // int bl = -1, br = i + 1, bm1, bm2, a1, a2;
        // while (br - bl > 2) {
        //     bm1 = (br + bl) / 2;
        //     bm2 = bm1 + 1;
        //     a1 = dp[i - 1][bm1] + a[i] + b[i] * bm1;
        //     a2 = dp[i - 1][bm2] + a[i] + b[i] * bm2;
        //     if (a1 >= a2) br = bm2;
        //     else bl = bm1; 
        // }
        // int best = -1, bestans = -INF;
        // for (int j = max(0ll, bl); j <= min(i, br); j++) {
        //     int qwe = dp[i - 1][j] + a[i] + b[i] * j;
        //     if ( qwe > bestans) {
        //         bestans = qwe; best = j;
        //     }
        // }
        // for (int j = best; j < n; j++) dp[i][j] = max(dp[i][j], bestans);
        // ans = max(ans, bestans);
        for (int j = 0; j <= i; j++) {
            // int curans = gett(pred, 0, 0, n - 1, j) + a[i] + b[i] * j;
            int curans = dp[i - 1][j] + a[i] + b[i] * j;
            // sett(1 - pred, 0, 0, n - 1, j, n - 1, curans);
            // dp[i][j] = max(dp[i][j], help + a[i] + b[i] * j);
            for (int jj = j; jj < n; jj++) dp[i][jj] = max(dp[i][jj], dp[i][j]);
            ans = max(ans, curans);
        }
        pred = 1 - pred;
    }
    // for (auto i : dp[n - 1]) cout << i << " ";
    cout << ans << endl;
    

    return 0;
}