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];
    ll ans = 0, cur = 0;
    ll j = 0;
    for (ll i = 0; i < n; ++i) {
        if (p[i] != -1) {
            while (j < p[i]) {
                cur += a[j] + b[j] * i;
                ++j;
            }
            ans = cur;
        } else {
            if (j == i) {
                cur = a[j] + b[j] * i;
            }
            j++;
            ans = max(ans, cur);
        }
    }
    cout << ans;
}
