#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve();

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

void solve(){
    int n;
    cin>>n;
    vector<pair<int,int>> a(n);
    for (int i=0;i<n;i++) cin>>a[i].first>>a[i].second;
    vector<int> p(n);
    for (int i=0;i<n;i++) cin>>p[i];
    int x=*max_element(p.begin(),p.end());
    int ans=0;
    int cur=0;
    for (int i=0;i<n;i++) {
        ans=max(ans,cur);
        if (i!=0 && a[i].second<0) cur+=(a[i].first+a[i].second*(1));
        else if (i==0 && a[i].second<0) cur+=(a[i].first);
        else cur+=(a[i].first+a[i].second*(i));
        ans=max(ans,cur);
    }
    cout<<ans;
}