// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(x) x.begin(), x.end()

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

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, ans, cur_ans;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    ans = 0;
    cur_ans = 0;
    vector<int> cur_best_suf = {0};
    vector<int> cur_add_to_push = {0};
    vector<int> time_taken = {0};
    for (int i = 0; i < n; i++) {
        cur_ans += a[i];
        cur_add_to_push.back() += b[i];
        int cur_time_taken = i;
        while (cur_best_suf.size() && cur_best_suf.back() + cur_add_to_push.back() < 0) {
            int prev_time_taken = 0;
            if ((int)cur_best_suf.size() != 1) {
                cur_add_to_push[cur_add_to_push.size() - 2] += cur_add_to_push[cur_add_to_push.size() - 1];
                prev_time_taken = time_taken[time_taken.size() - 2];
            }
            cur_ans -= (cur_best_suf.back() + cur_add_to_push.back() - b[i]) * (cur_time_taken - time_taken.back());
            cur_add_to_push.pop_back();
            cur_best_suf.pop_back();
            cur_time_taken = time_taken.back();
            time_taken.pop_back();
        }
        cur_best_suf.push_back(0);
        cur_add_to_push.push_back(0);
        time_taken.push_back(cur_time_taken);
        cur_ans += b[i] * cur_time_taken;
        ans = max(ans, cur_ans);
//        cout << cur_ans << " " << b[i] << " " << cur_time_taken << endl;
    }
    cout << ans << endl;
    return 0;
}
