#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;


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

    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 = 0;
    for (int i = 0; i < n; i++) dp[0][i] = a[0];

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

    return 0;
}