#include <bits/stdc++.h>

using ll = long long;

const ll INF = 2e9;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n), 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];
    }
    ll ans = INF;
    vector<ll> suff(n);
    suff[n - 1] = a[n - 1] + b[n - 1] * (n - 1);
    for (int i = n - 2; i >= 0; i--) {
        suff[i] = suff[i + 1] + a[i] + b[i] * i;
    }
    for (int i = 0; i < n; i++) {
        ans = min(suff[i], ans);
    }
    cout << max(0ll, suff[0] - ans);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    bool MULTITEST = 0;
    #ifdef egg
        MULTITEST = 1;
        freopen("test.txt", "r", stdin);
    #endif
    if (MULTITEST) {
        cin >> t;
    }
    while (t--) {
        solve();
    }
    return 0;
}
