#include <bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define ff first
#define ss second

void solve() {
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
    vector<int> b(n);
    for (int i = 0; i < n; i++) cin >> b[i];
    vector<int> arr(n, -1e17);
    int mx = a[0].ff;
    arr[0] = a[0].ff;
    for (int i = 1; i < n; i++) {
        int mx1 = -1e17;
        for (int j = 0; j <= i; j++) {
            mx1 = max(mx1, arr[j]);
            arr[j] = mx1 + a[i].ff + j * a[i].ss;
        }
        for (int j = 0; j < n; j++) mx = max(mx, arr[j]);
    }
    cout << mx;
}

signed main() {
//    freopen("input.txt", "rb", stdin);
//    freopen("output.txt", "wb", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
//    cin >> t;
    while (t--) solve();
}
