#include <bits/stdc++.h>
#include <experimental/random>

using namespace std;
using ll = long long;
using ld = long double;

const ll INF = 1e18, MOD = 998244353;

void solve();

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int q = 1;
    // cin >> q;
    while (q--) {
        solve();
    }
}

void solve() {
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    vector<ll> pref = {0};
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        pref.push_back(pref.back() + b[i]);
        if (i != 0) a[i] += a[i - 1];
    }

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

    ll ans = 0;
    vector<ll> st;
    ll sm = 0;
    for (int k = 0; k < n; k++) {
        if (!st.empty()) {
            sm += st.back() * b[k];
        }
        while (!st.empty() && pref[k + 1] - pref[st.back()] <= 0) {
            ll lst = 0;
            if (st.size() > 1) {
                lst = st[st.size() - 2];
            }
            sm -= (pref[k + 1] - pref[st.back()]) * (st.back() - lst);
            st.pop_back();
        }

        while (!st.empty() && pref[k + 1] - pref[st.back()] <= b[k]) {
            ll lst = 0;
            if (st.size() > 1) {
                lst = st[st.size() - 2];
            }
            sm -= (pref[k + 1] - pref[st.back()]) * (st.back() - lst);
            st.pop_back();
        }

        if (b[k] > 0) {
            ll lst = 0;
            if (!st.empty()) {
                lst = st.back();
            }
            sm += (k - lst) * b[k];
            st.push_back(k);
        }

        ans = max(ans, a[k] + sm);
    }
    cout << ans;
}