#pragma GCC optimize("O3, unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

const int inf = 1e18L;
const int mod = 998244353;
const int maxn = 1e6 + 1;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    ll sm = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
    }
    vector<vector<int> > dp(n, vector<int>(n, -inf)), pref_max(n, vector<int>(n, -inf));
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            if (!i) {
                dp[i][j] = a[i] + b[i] * j;
                pref_max[i][j] = (j ? max(pref_max[i][j - 1], dp[i][j]) : dp[i][j]);
            } else {
                dp[i][j] = pref_max[i - 1][j] + a[i] + b[i] * j;
            }
            ans = max(ans, dp[i][j]);
        }
        for (int j = 0; j < n; ++j) {
            pref_max[i][j] = (j ? max(pref_max[i][j - 1], dp[i][j]) : dp[i][j]);
        }
    }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
}
