#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define int long long

using namespace std;
using ll = long long;
ll mod = 998244353;
ll Mul(ll a, ll b) {return (a*b)%mod;}
ll Sum(ll a, ll b) {return (a+b)%mod;}
ll Sub(ll a, ll b) {return (a-b+mod)%mod;}

ll Pow(ll x, ll k) {
    ll answ = 1, step = x;
    while (k != 0) {
        if (k & 1) answ = Mul(answ, step);
        step = Mul(step, step);
        k >>= 1;
    }
    return answ;
}

ll Div(ll a, ll b) {return (a * Pow(b, mod-2))%mod;}

vector<vector<vector<ll>>> answ;
vector<ll> p;
void f(bool t, ll& n) {
    for (int i = 0; i < n; i++) {
        answ[0][0][t] = Sum(answ[0][0][t], Pow(p[i], i+1));
    }
    reverse(p.begin(), p.end());
    for (int i = 0; i < n; i++) {
        answ[1][0][t] = Sum(answ[1][0][t], Pow(p[i], i+1));
    }
    for (int i = 0; i < n; i++) p[i] = n - p[i] + 1;
    for (int i = 0; i < n; i++) {
        answ[1][1][t] = Sum(answ[1][1][t], Pow(p[i], i+1));
    }
    reverse(p.begin(), p.end());
    for (int i = 0; i < n; i++) {
        answ[0][1][t] = Sum(answ[0][1][t], Pow(p[i], i+1));
    }
}

void solve() {
    int n; cin >> n;
    vector<pair<ll, ll>> a(n);
    vector<ll> p(n);
    for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
    for (int i = 0; i < n; i++) cin >> p[i];
    ll answ = a[0].first, mx = a[0].first;
    ll cur = 0;
    for (int i = 0; i < n; i++) {
        if (p[i] == -1) {
            mx = max(mx, answ);
            continue;
        }
        for (int j = cur; j < p[i]; j++) {
            answ += a[j].first + min(i, j)*a[j].second;
            cur++;
        }
        mx = max(mx, answ);
    }
    if (cur < n) {
        for (int j = cur; j < n; j++) {
            answ += a[j].first + j*a[j].second;
            cur++;
        }
        mx = max(mx, answ);
    }
    cout << mx;
}

signed main() {
    cin.tie(0);
    solve();
    return 0;
}