#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pii pair<int, int>
#define ff first
#define ss second
#define ld long double
#define pb push_back
#define ins insert
#define int ll

mt19937 rnd(1488);

void solve(){
    int n;
    cin >> n;
    vector<pii> c(n);
    int tec = 0;
    int ans2 = 0;
    for (int i = 0; i < n; i++){
        cin >> c[i].ff >> c[i].ss;
    }
    int j = 0;
    int mx = 0;
    for (int i = 0; i < n; i++){
        int x;
        cin >> x;
        while (j < x){
            ans2 += c[j].ff + min(j, i) * c[j].ss;
            j++;
        }
    }
    int mx2 = 0;
    for (int i = j; i < n; i++){
        tec += c[i].ff + i * c[i].ss;
        mx2 = max(mx2, tec);
    }
    cout << ans2 + mx2 << "\n";
    return;
    vector<int> dp(n, -1e18);
    dp[0] = c[0].ff;
    int ans = 0;
    ans = max(ans, c[0].ff);
    for (int i = 1; i < n; i++){
        dp[0] += c[i].ff;
        for (int j = 0; j <= i; j++){
            dp[j] += c[i].ff + j * c[i].ss;
            if (j && dp[j - 1] + c[i].ss > dp[j]){
                dp[j] = dp[j - 1] + c[i].ss;
            }
            ans = max(ans, dp[j]);
        }
    }
    cout << ans << "\n";
}

int32_t main(){
    cin.tie(0)->ios_base::sync_with_stdio(0);
    #ifdef podureman
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif // podureman
    int _ = 1;
    //cin >> _;
    while (_--){
        solve();
    }
}
