#include <bits/stdc++.h>

// #pragma GCC optimize("Ofast")

using namespace std;

using ll = long long;
using ld = long double;

constexpr long long INF = 1e18, MOD = 1e9 + 7;


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    vector<ll> p(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
        cin >> b[i];
    }
    for (ll i = 0; i < n; ++i) {
        cin >> p[i];
    }
    ll ans = 0;
    vector<vector<ll>> dp(n, vector<ll> (n, -INF));
    dp[0][0] = a[0];
    for (ll i = 1; i < n; ++i) {
        ll mx = dp[i - 1][0];
        for (ll j = 0; j < i; ++j) {
            mx = max(mx, dp[i - 1][j]);
            dp[i][j] = mx + a[i] + j * b[i];
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans;
}