#include <iostream>
#include <vector>
#include <map>
#include <random>
using namespace std;
using ll = long long;
using ull = unsigned long long;


#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ROF(i, a, b) for(ll i = b; i >= a; --i)

mt19937 rnd(42);
mt19937_64 rnd64(52);

const int N = 200;
ll dp[N][N];
const ll inf = 1e15;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll n;
    cin >> n;
    vector<pair<ll,ll>> v(n);
    for (ll i = 0; i < n; ++i) {
        cin>> v[i].first >> v[i].second;
    }
    vector<ll> p(n + 1);
    ll ans = -inf;
    for (ll i = 1; i <= n; ++i) cin >> p[i];
    vector<ll> pref_max(n + 1);
    for (ll i = 1; i <= n; ++i) pref_max[i] = max(pref_max[i - 1], p[i - 1]);
    vector<ll> L(n + 1), R(n + 1, n);
    for (ll i = 1; i <= n; ++i) {
        R[i] = i - 1;
    }
    for (ll i = 0; i <= n; ++i) {
        for (ll j = 0; j <= n; ++j) {
            dp[i][j] = -inf;
        }
    }
    for (ll i = 0; i <= 0; ++i) {
        dp[1][i] = v[0].first + v[0].second * i;
        ans = max(ans, dp[1][i]);
    }
    for (ll i = 2; i <= n; ++i) {
        for (ll cur = 0; cur <= i - 1; ++cur) {
            for (ll prev = 0; prev <= i - 2; ++prev) {
                if (dp[i - 1][prev] != -inf) {
                    dp[i][cur] = max(dp[i][cur], dp[i - 1][prev]
                        + v[i - 1].first + cur * v[i - 1].second);
                    ans = max(ans, dp[i][cur]);
                }
            }
        }
    }
    cout << ans;
}