using ll = long long;
using namespace std;
#include <iostream>
#include <vector>
#include <algorithm>
#define all(x) (x).begin(), (x).end()
#pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
int main() {
    ll n;
    cin >> n;
    vector <ll> a(n), b(n), p(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    for (ll i = 0; i < n; ++i)
        cin >> p[i];
    vector <ll> p1 = p;
    for (ll i = n - 1; i > 0; --i)
        if (p1[i - 1] == -1)
            p1[i - 1] = p1[i];
    ll ans = 0, cur = 0;
    ll j = 0, i = 0;
    for (; i < n; ++i) {
        if (p1[i] == -1)
            break;
        while (j < p1[i]) {
            cur += a[j] + b[j] * i;
            j++;
        }
    }
    ans = cur;
    for (; j < n; ++j) {
        cur += a[j] + b[j] * i;
        ans = max(ans, cur);
    }
    cout << ans;
}