#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
using ll = long long;
using ld = long double;
mt19937 rnd(52);
ll mod = 998244353;
ld intersect(pair<ld, ld> l1, pair<ld, ld> l2) {
    return (l1.second - l2.second)/(l2.first-l1.first);
}
int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
#endif
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    vector<ll> prefsa(n+1);
    vector<ll> prefsb(n+1);
    for (int i = 0; i < n; i++) {
        prefsa[i+1] = prefsa[i] + a[i];
        prefsb[i+1] = prefsb[i] + b[i];
    }
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    vector<ll> dp(n+1, -1e18);
    dp[0] = 0;
    vector<pair<ld, ld>> st;
    vector<pair<ll, ll>> points = {{(ll)-1e18, (ll)0}};
    ll sum = 0;
    ll ans = 0;
    pair<ll, ll> to_find;
    for (int i = 1; i <= n; i++) {
        ld con = dp[i-1] - prefsb[i-1]*(i-1);
        ld k = i-1;
        pair<ld, ld> line = {k, con};
        while (st.size() >= 2 and intersect(st[st.size()-2], line) < intersect(st[st.size()-2], st[st.size()-1])) {
            st.pop_back();
            points.pop_back();
        }
        st.push_back(line);
        if (st.size()>=2) {
            points.push_back({intersect(st[st.size()-1], st[st.size()-2]), st.size()-1});
        }
        /*for (auto [b, k] : st) {
            cout << b << ' ' << k << '\n';
        }
        for (auto [a, b] :points) {
            cout << a << ' ' << b << '\n';
        }
        cout << endl;*/
        to_find = {(ll)prefsb[i], (ll)-1};
        auto x = *prev(lower_bound(points.begin(), points.end(), to_find));
        //cout << x.first << ' ' << x.second << "F\n";
        dp[i] = prefsb[i]*st[x.second].first + st[x.second].second;
        //cout << dp[i] << endl;
        sum+=a[i-1];
        ans = max(ans, dp[i]+sum);
    }
    cout << ans << '\n';
    return 0;
}