// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef __int128 lll;

const ll inf=1e18+1,mod=998244353;
const ld eps=1e-9,pi=acos(-1);
#define all(a) a.begin(), a.end()
#define mpp make_pair
#define F first
#define S second

mt19937_64 rng(234);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n;cin>>n;
    vector<ll>a(n+1),b(n+1);
    for (ll i=1;i<=n;i++)
        cin>>a[i]>>b[i];
    vector<ll>w(1),h(1);
    for (ll i=1;i<=n;i++) {
        ll x;cin>>x;
        if (x!=-1) {
            w.push_back(i);
            h.push_back(x);
        }
    }
    ll ans=0;
    for (ll i=1;i<w.size();i++) {
        for (ll j=h[i-1]+1;j<=h[i];j++)
            ans+=w[i-1]*b[j]+a[j];
    }
    ll sm=0,mx=0;
    for (ll i=h.back()+1;i<=n;i++) {
        sm+=a[i]+b[i]*w.back();
        if (mx<sm)
            mx=sm;
    }
    cout<<ans+mx;
}