#include <bits/stdc++.h>

using namespace std;
using ll = long long;

struct Node {
    ll a, b;
};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n;
    cin >> n;

    vector<Node> a(n);
    for (ll i = 0; i < n; ++i)
        cin >> a[i].a >> a[i].b;

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

    vector<ll> suf(n + 1);
    for (ll i = n - 1; i >= 0; --i)
        suf[i] = suf[i + 1] + a[i].a + i * a[i].b;

    ll ans = 0;
    for (ll i = 0; i < n && suf[i] >= 0; ++i) {
        ans += a[i].a + i * a[i].b;
    }

    cout << ans;
}