#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll infll = 1e18;

template<typename T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) {
        is >> i;
    }
    return is;
}

int32_t main() {
#ifdef LOCAL
    freopen("C:\\work\\input.txt", "r", stdin);
#else
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    for (auto &[a, b] : v) {
        cin >> a >> b;
    }
    vector<int> p(n);
    cin >> p;
    vector<vector<ll>> dp(n, vector<ll>(n + 1, -infll));
    dp[0][0] = v[0].first + 0 * v[0].second;
    for (int i = 0; i + 1 < n; ++i) {
        for (int t1 = 0; t1 <= i; ++t1) {
            for (int t2 = t1; t2 <= i + 1; ++t2) {
                dp[i + 1][t2] = max(dp[i + 1][t2], dp[i][t1] + v[i + 1].first + t2 * 1ll * v[i + 1].second);
            }
        }
    }
    ll ans = -infll;
    for (int i = 0; i < n; ++i) {
        for (int t = 0; t <= n; ++t) {
            ans = max(ans, dp[i][t]);
        }
    }
    cout << ans << "\n";
    return 0;
}
