#include <bits/stdc++.h>

using namespace std;

const long long MOD = 998244353;

int main()
{
    int n;
    cin >> n;
    vector <pair <long long, long long>> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i].first >> v[i].second;
    }
    vector <int> p(n);
    int j = 0;
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        if (p[i] == -1 && j == i) {
            ans += max((long long) 0, (v[j].first + v[j].second * i));
        } else {
            while (j < p[i]) {
                ans += (v[j].first + v[j].second * i);
                j++;
            }
        }
    }
    cout << ans;
    return 0;
}
