#include<bits/stdc++.h>
#define int long long
using namespace std;

const int INF = 1e18;

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

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

    solve();
}
