#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

// #pragma GCC optimize("O3,unroll-loops,fast-math")
// #pragma GCC target("avx2,bmi2")

using namespace std;
using namespace chrono;

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

template<typename T, typename Cmp = less<T>>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, Cmp,
__gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
inline int sz(const T& x) {
    return (int)x.size();
}

const int MAXN = 1e6;
const ll INF = 4e18;
const int ALPH = 26;
const int MAXLOG = 20;
const ll MOD = 998244353;
const ld EPS = 1e-8;

const ull SEED = steady_clock::now().time_since_epoch().count();
mt19937_64 rnd(67);

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& i : p) {
        cin >> i;
    }
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, -INF));
    for (int i = 0; i <= n; i++) {
        dp[0][i] = 0;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            for (int k = 0; k <= j - 1; k++) {
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i - 1] + (ll)b[i - 1] * j);
            }
        }
    }
    ll ans = -INF;
    for (int i = 1; i <= n; i++) {
        ans = max(ans, *max_element(dp[i].begin(), dp[i].end()));
    }
    cout << ans;
}

int main() {
    #ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int test_cases = 1;
    // cin >> test_cases;
    while (test_cases--) solve();
    return 0;
}
