#include <bits/stdc++.h>

#define int long long

using namespace std;
using ll = long long;
using ld = long double;

const int inf = 1e9;
const int mod = 998244353;


void go() {
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i].first >> v[i].second;
    }

    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }

    p.push_back(n);
    int ans = 0;
    int mx = 0;
    int j = 0;
    for (int i = 0; i <= n; i++) {
        if (p[i] == -1) {
            continue;
        }
        
        while (j < p[i]) {
            ans += v[j].first + i * v[j].second;
            mx = max(mx, ans);
            j++;
        }
        mx = max(mx, ans);
    }

    cout << mx << '\n';
}

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

    int t = 1;
    // cin >> t;
    while (t--) {
        go();
    }
}