#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e18;
signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int ans = 0;
    vector<vector<int>> dp(2, vector<int>(n + 1, -inf));
    int cur_sm = 0;
    dp[0][0] = cur_sm;
    for (int i = 0; i < n; i++) {
        cur_sm += a[i];
        dp[0][i + 1] = cur_sm;
        ans = max(ans, cur_sm);
    }
    for (int i = 1; i < n; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i % 2][j] = dp[(i + 1) % 2][j];
        }
        for (int j = 1; j <= n; j++) {
            int cur_sm = 0;
            for (int k = j; k >= 1; k--) {
                if (k - 1 < i) break;
                cur_sm += a[k - 1] + b[k - 1] * i;
                int add = dp[(i - 1) % 2][k - 1];
                dp[i % 2][j] = max(dp[i % 2][j], cur_sm + add);
                ans = max(ans, dp[i % 2][j]);
            }
        }
    }
    cout << ans << '\n';
}