#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll

using pii = pair<int, int>;

void solve(){
    int n;
    cin >> n;
    vector<int> a(n), b(n), t(n, -1), p(n);
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    for(int i = 0; i < n; i++){
        cin >> p[i];
        if(p[i] == -1){
            if(i == 0){
                p[i] = 1;
            } else {
                p[i] = p[i - 1];
            }   
        }
    }
    int i = 0;
    for(int j = 0; j < n; j++){
        while(i < n && i < p[j]){
            t[i] = j; 
            i++;
        }
    }
    int ans = 0;
    int anss = 0;
    for(int i = 0; i < n; i++){
        ans += a[i] + b[i] * t[i];
        anss = max(anss, ans);
    }
    cout << anss << '\n';
}

signed main(){
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}