#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
using vl = __int128_t;
using ld = long double;
using ordered_set = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const ll mod = 998244353;
void solve() {
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (ll i = 0; i < n; i++) cin >> a[i] >> b[i];
    vector<ll> p(n);
    for (ll& x : p) cin >> x;
    vector<vector<ll>> dp(n, vector<ll>(n, -1e18));
    for (ll x = 0; x <= 0; x++) {
        dp[0][x] = a[0] + b[0] * x;
    }
    for (ll i = 1; i < n; i++) {
        for (ll j = 0; j <= i; j++) {
            for (ll k = 0; k <= j; k++) {
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i] + b[i] * j);
            }
        }
    }
    ll ans = -1e18;
    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j <= i; j++) ans = max(ans, dp[i][j]);
    }
    cout << ans;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
