#include <bits/stdc++.h>

using namespace std;
#define int long long
const int INF = 1e18 + 1;
int n;
vector <int> a;
vector <int> b;
vector <int> p;
int ans = 0;
vector <int> t, t2;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    a.resize(n + 1);
    b.resize(n + 1);
    p.resize(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    t.push_back(a[1]);
    for (int i = 2; i <= n; i++) {
        t.push_back(-INF);
        t2 = t;
        fill(t.begin(), t.end(), -INF);
        for (int j = 0; j <= i - 1; j++) {
            if (j > 0) {
                t[j] = t[j - 1];
            }
            t[j] = max(t[j], t2[min(j, i - 2)] + a[i] + b[i] * j);
        }
        ans = max(ans, t[i - 1]);
    }
    cout << ans;
}

