#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2,popcnt")
#pragma GCC target("tune=native")

using namespace std;

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpi vector<pair<int>>
#define pi pair<int, int>
#define vvpi vector<vector<pair<int, int>> >
#define sz(a) (int)a.size()

int mod1 = 2286661337;
int mod2 = 91138233;
int mod3 = 97266353;

struct fenwick {
    int n;
    vi f;
    explicit fenwick(int &n): n(n) {
        f.resize(n, 0);
    }

    void upd(int x, int val) {
        for (int i = x; i <= n; i += i & -i) {
            f[i] += val;
        }
    }

    int pref(int x) {
        int sum = 0;
        for (int i = x; i >= 0; i -= i & -i) {
            sum += f[i];
        }
        return sum;
    }

    int sum(int l, int r) {
        return pref(r) - pref(l-1);
    }
};

struct sparse {
    int n, LOG;
    vi lg;
    vvi s;

    explicit sparse(vi a) : n(sz(a)) {
        LOG = ceil(log2(n+1));
        lg.resize(n+1);
        s.resize(LOG, vi(n+1, INT_MAX));

        for (int i = 2; i <= n; i++) lg[i] = lg[i/2] + 1;
    }
};

void solve_a() {
    int n, q; cin >> n >> q;
    vi a(n);
    for (int&i : a) cin >> i;
    while (q--) {
        int t; cin >> t;
        if (t == 1) {
            int x; cin >> x;
        } else {
            int y; cin >> y;

        }
    }
}

void solve_d() {
    int n; cin >> n;
    vi a(n), b(n), p(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int&i : p) cin >> i;
    int cur = 0;
    vi t(n, -1);
    int cr = 0;
    int k = 0;
    for (int i = 0; i < n; i++) {
        if (p[i] != -1) {
            p[i]-=cr;
            for (int j = k; j < p[i]+k; j++) {t[j] = i;}
            k = p[i] + k;
            cr += p[i];
        }
    }
    int mx = 0;
    for (int i = 0; i < n; i++) {
        if (t[i] == -1) break;
        mx += a[i] + t[i]*b[i];
    }
    cur = mx;
    for (int i = 0; i < n; i++) {
        if (t[i] == -1) continue;
        //cout << cur << endl;
        cur += a[i] + b[i]*i;
        mx = max(cur, mx);
    }
    cout << mx;
}

signed main() {
    int t = 1;
    //cin >> t;
    while (t--) {
        solve_d();
    }
}