#include<bits/stdc++.h>

#define len(v) (int)v.size()
#define all(v) v.begin(), v.end()

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

void solve() {
    int n;
    cin >> n;
    vector<pair<ll, ll>> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first >> a[i].second;
    }
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    vector<vector<ll>> dp(n, vector<ll>(n, -2e18));
    dp[0][0] = a[0].first;
    ll ans = dp[0][0];
    //cout << dp[0][0] << endl;
    for (ll i = 1; i < n; ++i) {
        for (ll time = 0; time <= i; ++time) {
            for (ll time1 = min(time, i - 1); time1 >= 0; --time1) {
                dp[i][time] = max(dp[i][time], dp[i - 1][time1] + a[i].first + a[i].second * time);
            }
            ans = max(ans, dp[i][time]);
        }
        //cout << endl;
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }
}