#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pii pair<int, int>
#define ff first
#define ss second
#define ld long double
#define pb push_back
#define ins insert
#define int ll

mt19937 rnd(1488);

void solve(){
    int n;
    cin >> n;
    vector<pii> c(n);
    for (int i = 0; i < n; i++){
        cin >> c[i].ff >> c[i].ss;
    }
    int j = 0;
    int ans = 0;
    for (int i = 0; i < n; i++){
        int x;
        cin >> x;
        int prj = j;
        while (j < x){
            if (c[j].ss <= 0){
                ans += c[j].ff + min(i, (prj + 1)) * c[j].ss;
            }
            else{
                ans += c[j].ff + min(j, i) * c[j].ss;
            }
            j++;
        }
    }
    int tec = 0;
    int mx = 0;
    for (int i = j; i < n; i++){
        if (c[i].ss <= 0){
            tec += c[i].ff;
        }
        else{
            tec += c[i].ff + c[i].ss * i;
        }
        mx = max(mx, tec);
    }
    cout << ans + mx << "\n";
}

int32_t main(){
    cin.tie(0)->ios_base::sync_with_stdio(0);
    #ifdef podureman
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif // podureman
    int _ = 1;
    //cin >> _;
    while (_--){
        solve();
    }
}
