#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll

using pii = pair<int, int>;

void solve(){
    int n;
    cin >> n;
    vector<int> a(n), b(n), t(n, -1);
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    int i = 0;
    int pi = 0;
    int pj = n;
    int last = 0;
    bool started = false;
    for(int j = 0; j < n; j++){
        int x;
        cin >> x;
        if(started){
            if(x < 0){
                continue;
            }
            pj = x;
            i = pj;
            started = false;
            continue;                       
        }
        if(x < 0){
            pi = last;
            started = true;
            continue;
        }
        while(i < x){
            t[i] = j; 
            i++;
        }
    }
    for(int i = 0; i < n; i++){
        if(t[i] == -1){
            t[i] = i;
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans += a[i] + b[i] * t[i];
    }
    cout << ans << '\n';
}

signed main(){
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}