#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;

using ll = long long;

// template <class T> using ordered_set = tree<T, nullptr, less<T>, rb_tree_tag, tree_node_statistics_update>;

const ll inf = ll(1e18) + 2;
const ll mod = 998244353;

struct node {
    ll x;
    ll p;

    node(ll x_ = -inf, ll p_ = 0) {
        x = x_;
        p = p_;
    }
};

node c(node a, node b) {
    node j;
    j.x = a.x + b.x;
    j.p = 0;
    return j;
}

struct st {

};

ll bp(ll a, ll n) {
    if (n == 0) {
        return 1 % mod;
    }
    ll k = bp(a, n / 2);
    if (n % 2 == 0) {
        return (k * k) % mod;
    }
    return (((k * k) % mod) * a) % mod;
}

inline void solve() {
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    ll ans2 = 0;
    for (ll i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        ans2 += a[i];
    }
    vector<ll> e(n);
    for (ll i = 0; i < n; i++) {
        cin >> e[i];
    }
    vector<vector<ll>> d(n + 1, vector<ll>(n, -inf));
    for (ll i = 1; i < n + 1; i++) {
        for (ll j = 0; j < i; j++) {
            if (i == 1) {
                d[i][j] = a[i - 1] + j * b[i - 1];
            }
            for (ll w = 0; w <= min(j, i - 2); w++) {
                d[i][j] = max(d[i][j], d[i - 1][w] + a[i - 1] + j * b[i - 1]);
            }
        }
    }
    ll ans = -inf;
    for (ll i = 0; i < n + 1; i++) {
        ans = max(ans, *max_element(d[i].begin(), d[i].end()));
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll q = 1;
    // cin >> q;
    while (q--) {
        solve();
    }
    return 0;
}
