
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <unordered_map>
using namespace std;
using ll = long long;
using vll = vector<ll>;
ll mod = 998244353;
ll pow(ll n, ll k) {
    ll ans = 1;
    while (k) {
        if (k & 1) ans = ans * n % mod;
        n = n * n % mod;
        k >>= 1;
    }
    return ans;
}
struct LiChao {
    struct Line {
        ll a = 0, b = 0;
        ll operator()(ll x) {
            return a + b * x;
        }
    };
    ll n;
    vector<Line> tree;
    LiChao(ll n) : n(n), tree(4 * n) {
    }
    void update(Line line, ll l, ll r, ll v) {
        if (l == r) {
            tree[v] = line;
            return;
        };
        ll m = (l + r) >> 1;
        if (tree[v](m) < line(m)) {
            swap(line, tree[v]);
        }
        if (tree[2 * v + 1](l) < line(l)) {
            update(line, l, m, 2 * v + 1);
        } else if (tree[2 * v + 2](r) < line(r)) {
            update(line, m + 1, r, 2 * v + 2);
        }
    }
    ll get(ll x, ll l, ll r, ll v) {
        if (l == r) {
            return tree[v](x);
        }
        ll m = (l + r) >> 1;
        if (x <= m) return max(tree[v](x), get(x, l, m, 2 * v + 1));
        else return max(tree[v](x), get(x, m + 1, r, 2 * v + 2));
    }
    void update(Line l) {
        update(l, 0, n - 1, 0);
    }
    ll get(ll x) {
        return get(x, 0, n - 1, 0);
    }
};
void solve() {
    ll n;
    cin >> n;
    vll a(n), b(n);
    ll mx_b = -1e18;
    for (ll i = 0; i < n; ++i) cin >> a[i] >> b[i], mx_b = max(mx_b, b[i]);
    vll p(n);
    for (ll i = 0; i < n; ++i) cin >> p[i];
    if (mx_b <= 0) {
        ll ans = 0;
        ll sum = 0;
        for (ll i = 0; i < n; ++i) sum += a[i], ans = max(ans, sum);
        cout << ans << endl;
        return;
    }
    ll ans = 0;
    ll b_sum = 0;
    ll res = 0;
    ll pr = 0;
    vll pref(n + 1, 0);
    for (ll i = 0; i < n; ++i) pref[i + 1] = pref[i] + b[i];
    LiChao tree(1e6);
    for (ll i = 0; i < n; ++i) {
        ans += a[i];
        if (b[i] >= 0) {
            b_sum += b[i] * i;
        } else {
            b_sum = tree.get(pref[i + 1]);
            tree.update({b_sum - i * pref[i + 1], i});
        }
        res = max(res, ans + b_sum);
    }
    cout << res << endl;
}

int main() {
    //freopen("in.txt", "r", stdin);
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t = 1;
    for (int i = 0; i < t; ++i) {
        solve();
    }
    cout << endl;
    return 0;
}
