#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define cin(v) for (auto& el : v) {cin >> el;}
#define cout(v) for(auto& el : v) {cout << el << " ";} cout << "\n";

using namespace std;
using ll = long long;
using db = double;
const ll MOD = 1e9 + 7;
const ll MOD2 = 1072005019;
const ll MOD3 = 998244353;

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);
    cin(p);
    vector<vector<ll>> dp(n + 1, vector<ll>(n, -1e18));
    dp[0][0] = 0;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int t = 0; t <= i; t++) {
            ans = max(ans, dp[i][t]);
            for (int new_t = t; new_t <= i; new_t++) {
                dp[i + 1][new_t] = max(dp[i + 1][new_t], dp[i][t] + a[i] + 1ll * b[i] * new_t);
            }
        }
    }
    for (int t = 0; t < n; t++) {
        ans = max(ans, dp[n][t]);
    }
    cout << ans;
    return;
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int multitest = 0;
    if (multitest) {
        int t;
        cin >> t;
        while (t--) {
            solve();
        }
    } else {
        solve();
    }
}