#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <iomanip>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#define ll long long
#define X first
#define Y second
#define endl '\n'
using namespace std;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
const int MAXN=1010000;
ll a[MAXN],b[MAXN];
int n;
int p[MAXN];
int ma=0;
void read()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
    }
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        ma=max(ma,x);
    }
}
signed main()
{
    speed();
    read();
    ll ans=0;
    ll bans=0;
    for(int i=1;i<=n;i++)
    {
        if(b[i]<0)ans+=a[i];
        else ans+=a[i]+(i-1)*b[i];
        if(i>=ma)
        bans=max(ans,bans);
    }
    cout<<bans<<endl;
    return 0;
}