#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
using ll = long long;

# define len(x) ((ll) x.size())
const ll inf = 1e18;

const ll N = 5001;
ll dp[N][N];

void solve() {
    ll n;
    cin >> n;

    vector<pair<ll, ll>> a(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i].first >> a[i].second;
    }

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

    for (ll i = 0; i < n; ++i) {
        for (ll j = 0; j <= i; ++j) {
            dp[i][j] = -inf;
        }
    }

    ll mx = a[0].first;
    dp[0][0] = a[0].first;
    for (ll i = 1; i < n; ++i) {
        for (ll j = 0; j <= i; ++j) {
            for (ll k = 0; k <= min(i - 1, j); ++k) {
                if (dp[i - 1][k] == -inf) { continue; }
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i].first + a[i].second * j);
                mx = max(mx, dp[i][j]);
            }
        }
    }

    cout << mx << "\n";
}

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

    solve();

    return 0;
}