#include<bits/stdc++.h>

using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int n;
    cin >> n;
    vector<pair<int, int>> q(n);
    for (int i = 0; i < n; i++) {
        cin >> q[i].first >> q[i].second;
    }
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    vector<int> t(n);
    int lastp = 0;
    for (int i = 0; i < n; i++) {
        for (int j = lastp; j < p[i]; j++) {
            t[j] = i;
        }
        lastp = p[i];
    }
    vector<int> pref(n + 1, 0);
    int lastp = 0;
    for (int i = 0; i < n; i++) {
        pref[i + 1] = pref[i] + q[i].first + lastp * q[i].second;
        lastp = p[i];
    }
    int ind = 0;
    for (int i = 1; i <= n; i++) {
        if (pref[ind] < pref[i]) ind = i;
    }
    cout << pref[ind];
    return 0;        
}