#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
const ll MAXN = 1e6 + 6;
const ll inf = 1e17 + 7;
const ll mod = 998244353;
const ll prod = 53;
mt19937 rnd(2);
ll p[MAXN];

int main() {
    ll n, a, b;
    cin >> n;
    vector<pair<ll, ll> > arr;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        arr.push_back({a, b});
    }
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    ll ind = -1;
    ll res = 0;
    ll res1 = res;
    if (p[n-1] == -1 && ind < n-1) {
        for (ll i = ind+1;i<n;i++) {
            res += arr[i].first;
            res += arr[i].second * i;
            res1 = max(res1,res);
        }
    }
    cout << res1 << "\n";
}
