#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define ub upper_bound
#define lb lower_bound
#define pll pair<ll, ll>

mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

pll a[1000100];

ll p[1000100];

ll dp[1000100];

void solve() {
    ll n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i].f >> a[i].s;
    }
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    ll ans = 0;
    ll nw = 0;
    for (int i = 0; i < n; i++) {
        nw += a[i].f;
        ll p_max = 0;
        for (int j = 0; j <= i; j++) {
            p_max = max(dp[j], p_max);
            dp[j] = p_max + a[i].s * j;
            ans = max(ans, dp[j] + nw);
        }
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
    //cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}
