#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

void solve() {
    int n;
    cin >> n;
    vector <pair <ll, ll>> a(n);
    for (auto &[x, y] : a) {
        cin >> x >> y;
    }
    vector <int> p(n);
    for (auto &e : p) {
        cin >> e;
    }
    vector <vector <ll>> dp(n + 1, vector <ll> (n + 1, -1e18));
    vector <vector <ll>> mx(n + 1, vector <ll> (n + 1, -1e18));
    fill(all(mx[0]), 0);
    ll ans = -1e18;
    for (int i = 1; i <= n; i++) {
        for (int j = i; j > 0; j--) {
            for (int time = 0; time < j; time++) {
                ll sum = 0;
                for (int k = j - 1; k < j; k++) {
                    sum += a[k].first + (ll)time * a[k].second;
                }
                if (mx[j - 1][max(0, time - 1)] != -1e18) {
                    dp[i][time] = max(dp[i][time], mx[j - 1][max(0, time - 1)] + sum);
                }
            }
        }
        ll mxx = -1e18;
        for (int time = 0; time <= n; time++) {
            mxx = max(mxx, dp[i][time]);
            mx[i][time] = mxx;
            ans = max(ans, dp[i][time]);
        }
    }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}

// Halal code
