#ifdef ONPC
    #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

using namespace std;

#define all(v) begin(v), end(v)

using ll = long long;

const ll INF = 1e18L + 10;

void test_case() {
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    vector<ll> p(n);
    for (auto &i : p) {
        cin >> i;
    }

    ll cur = 0;
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, -INF));
    dp[0][0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= n; ++j) {
            for (int k = j; k <= i; ++k) {
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i] + b[i] * k);
            }
        }
    }

    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans = max(ans, *max_element(all(dp[i])));
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
//    cin >> t;
    while (t--) {
        test_case();
    }

    return 0;
}
