#include <bits/stdc++.h>

using namespace std;

#define int ll
#define endl '\n'

typedef long long ll;

void solve() {
#ifdef LOCAL
    cout << "___NEW___" << endl;
#endif
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    vector<int> suff(n + 1);
    for (int i = n - 1; i > -1; i--) {
        suff[i] = suff[i + 1] + a[i].second;
    }
    int ans = 0;
    // for (int i = 0; i < n; i++) {
    // }
    int cur = 0;
    int ANS = 0;
    for (int i = 0; i < n; i++) {
        if (suff[i] <= 0) {
        } else {
            cur = i;
        }
        ans += a[i].second * cur;
        ans += a[i].first;
        ANS = max(ans, ANS);
    }
    cout << ANS << endl;
}

signed main() {
#ifdef LOCAL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int qwe = 1;
#ifdef LOCAL
    cin >> qwe;
#endif
    for (int _ = 0; _ < qwe; _++) {
        solve();
    }
    return 0;
}