#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <set>
#include <cstring>
#define control cout<<"e ne"<<endl;
#define endl '\n'
#define int long long
using namespace std;
int n,a[1048576],b[1048576],p[1048576],mx,mp,pf[1048576],xf[1048576];
void speed()
{
 ios_base::sync_with_stdio(false);
 cin.tie(0);
}
signed main()
{
    /*
    #ifdef ONLINE_JUDGE
    freopen("txt.in","r",stdin)
    freopen("txt.out","w",stdout)
    #endif
    */
    speed();
    cin>>n;
    int sum=0;
    vector <int> v;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
        xf[i]=xf[i-1]+a[i];
        pf[i]=pf[i-1]+b[i];
        mx=max(mx,sum);
        if(b[i]>0)
        {
            v.push_back(i);
        }
    }
    reverse(v.begin(),v.end());
    for(int i=1;i<=n;i++)
    {
        cin>>p[i];
        mp=max(mp,p[i]);
    }
    for(int k=1;k<=n;k++)
    {
        int sum=xf[k];
        int tsum=0,last=k;
        for(auto i:v)
        {
            if(i>k)continue;
            if(pf[last]-pf[i-1]>0)
            {
                sum+=(pf[last]-pf[i-1])*(i-1);
                last=i-1;
            }
        }
        //cout<<k<<" "<<sum<<endl;
        mx=max(mx,sum);
    }
    cout<<mx<<endl;
    return 0;
}
