#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main() {
    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 (int& i : p) cin >> i;
    vector<vector<int>> dp(n, vector<int>(n));
    for (int t = 0; t < n; t++) {
        dp[0][t] = a[0];
    }
    int ans = max(0ll, dp[0][0]);
    ans = 0;
    for (int i = 0; i < n; i++) {
        ans += a[i];
    }
    cout << ans << "\n";
    return 0;
    for (int i = 1; i < n; i++) {
        for (int t = 0; t <= i; t++) {
            dp[i][t] = dp[i - 1][t] + a[i] + b[i] * t;
            // cout << i << " " << t << ": " << dp[i][t];
            ans = max(ans, dp[i][t]);
        }
        for (int t = 1; t <= i; t++) {
            dp[i][t] = max(dp[i][t], dp[i][t - 1]);
        }
        for (int t = i + 1; t < n; t++) {
            dp[i][t] = dp[i][t - 1];
        }
    }
    cout << ans << "\n";
}