#include <bits/stdc++.h>

#define int long long

using namespace std;
using ll = long long;
using ld = long double;
using sll = __int128;

const int maxn = 5010, inf = 1e16;

int dp[maxn][maxn];
int a[maxn], b[maxn];

void solve() {
    int n;
    cin >> n;
    for (int i = 0; i <= n; i++) {
        fill(dp[i], dp[i] + n + 1, -inf);
    }
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
    }
    vector<int> p(n + 1);
    for (int i = 1; i <= n; i++) cin >> p[i];
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int t = 0; t < i; t++) {
            for (int j = 0; j <= min(i - 1, t); j++) {
                dp[i][t] = max(dp[i][t], dp[i - 1][j] + a[i] + b[i] * t);
            }
        }
    }
    int mx = -inf;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) mx = max(mx, dp[i][j]);
    }
    cout << mx;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int test = 1;
    // cin >> test;
    while (test--) {
        solve();
    }
}