#include <bits/stdc++.h>

#define int long long

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

const int inf = 1e12;
const int mod = 998244353;


void go() {
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i].first >> v[i].second;
    }

    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }

    vector<vector<int>> dp(n, vector<int> (n, -inf));
    int cnt = 0;
    int mx = 0;


    for (int i = 0; i < n; i++) {
        cnt += v[i].first;
        dp[i][0] = cnt;
        mx = max(mx, cnt);

        for (int j = 1; j <= i; j++) {
            if (i != 0) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j] + v[i].first + v[i].second * j);
            }
            int cnt1 = 0;
            for (int k = i - 1; k >= j - 1; k--) {
                cnt1 += v[k + 1].first + v[k + 1].second * (j);
                dp[i][j] = max(dp[i][j], dp[k][j - 1] + cnt1);
            }
            mx = max(mx, dp[i][j]);
        }
    }
    cout << mx << '\n';
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    // cin >> t;
    while (t--) {
        go();
    }
}