#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define all(a) (a).begin(), (a).end()

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin >> t;
    while (t--) solve();
}
#define int ll
void solve() {
    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 (auto& x : p) cin >> x;
    ll cur = 0, ans = -1e18;
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        while (cnt < max(p[i], i + 1)) {
            cur += a[cnt] + b[cnt] * i;
            ++cnt;
        }
        ans = max(ans, cur);
    }
    cout << ans << '\n';
}