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

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i] >> b[i];
    }
    vector<int> p(n);
    for(int &x : p) cin >> x;
    int ans = 0, sum = 0;
    vector<int> x = {0}, c = {-(int)1e18};
    for(int i = 0; i < n; ++i){
        x.push_back(i);
        c.push_back(-b[i]);
        sum += a[i] + b[i]*i;
        while(c.back() > 0){
            int y = x.back(), d = c.back();
            x.pop_back(); c.pop_back();
            sum += (y - x.back()) * d;
            c.back() += d;
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
}