#include <bits/stdc++.h>

using namespace std;
using ll = int64_t;
const ll inf = 1e18;
void solve();

template<typename T, typename T1> T remax(T& x, T1 y) { if (x < y) x = y; return x; }
template<typename T, typename T1> T remin(T& x, T1 y) { if (y < x) x = y; return x; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
//    cin >> t;
    while (t--) solve();
}
#define int int64_t

void solve() {
    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 (auto& x : p) cin >> x;
    vector<vector<int>> dp(n, vector<int>(n, -inf));
    dp[0][0] = a[0];
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= i; ++j) {
            for (int k = 0; k <= i - 1; ++k) {
                remax(dp[i][j], dp[i - 1][k] + a[i] + b[i] * j);
            }
        }
        remax(ans, *std::max_element(dp[i].begin(), dp[i].end()));
    }
    cout << ans;
//    cout << *std::max_element(dp[n - 1].begin(), dp[n - 1].end());
}