#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];
    deque<pair<pair<int,int>,pair<int,int>>> q;
    pair<int,int> cur={0,0};
    for (int i=n-1;i>=0;i--) {
        cur.first+=a[i].first;
        cur.second+=a[i].second;
        if (a[i].second>=0 || i==0) {
            q.push_front({{cur.first,cur.second*i},{a[i].first,a[i].second*i}});
            cur={0,0};
        }
    }

    int qwq=0;
    int ans=0;
    for (int i=0;i<q.size();i++) {
        ans=max(ans,qwq+(q[i].second.first+q[i].second.second));
        qwq+=(q[i].first.first+q[i].first.second);
    }
    cout<<max(ans,qwq);
}