#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")
// #pragma GCC optimize("unroll-loops")

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod = 998244353;

void solve() {
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    bool f1 = true;
    bool f2 = true;
    for (ll i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        if (b[i] > 0) {
            f1 = false;
        }
        if (b[i] < 0) {
            f2 = false;
        }
    }
    vector<ll> p(n);
    bool flag = true;
    for (ll i = 0; i < n; i++) {
        cin >> p[i];
        if (p[i] != -1) {
            flag = false;
        }
    }
    if (f1 && flag) {
        ll ans = 0;
        ll s = 0;
        for (ll i = 0; i < n; i++) {
            s += a[i];
            ans = max(ans, s);
        }
        cout << ans;
        return;
    }
    if (f2 && flag) {
        ll ans = 0;
        ll s = 0;
        for (ll i = 0; i < n; i++) {
            s += a[i] + i * b[i];
            ans = max(ans, s);
        }
        cout << ans;
        return;
    }
    if (flag) {
        ll ans = 0;
        vector<vector<ll>> dp(n, vector<ll> (n, -1e10));
        dp[0][0] = a[0];
        vector<ll> pref_max(n, a[0]);
        for (ll i = 1; i < n; i++) {
            for (ll t = 0; t <= i; t++) {
                ll dop = a[i] + t * b[i];
                dp[i][t] = max(dp[i][t], pref_max[t] + dop);
            }
            pref_max[0] = dp[i][0];
            for (ll t = 1; t < n; t++) {
                pref_max[t] = max(pref_max[t - 1], dp[i][t]);
            }
        }
        for (ll i = 0; i < n; i++) {
            for (ll t = 0; t < n; t++) {
                ans = max(ans, dp[i][t]);
            }
        }
        cout << ans;
    }
}

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