#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> 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];
    }
    int min_must = *max_element(p.begin(), p.end());
    int res = -1000000000000000000, ans = 0;
    vector<int> mnTm(n), mxTm(n);
    int prv = 0;
    for (int i = 0; i < n; ++i) {
        mnTm[i] = 0;
        mxTm[i] = i;
    }
    if (min_must <= 0) {
        res = 0;
    }
    for (int i = 0; i < n; ++i) {
        if (b[i] <= 0) {
            ans += a[i] + mnTm[i] * b[i];
        } else {
            ans += a[i] + mxTm[i] * b[i];
        }
        if (i + 1 >= min_must) {
            res = max(res, ans);
        }
    }
    cout << res << "\n";
}