#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const int inf = 0x3f3f3f3f;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(x) 67
#endif
const ll mod = 998'244'353;
const ll INF = 2e16;

void solve() {
    int n; cin >> n;
    vector<pii> c(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i].first >> c[i].second;
    }
    vector<int> p(n);
    for (int &i : p) {
        cin >> i;
        assert(i == -1);
    }
    vector<vector<ll>> dp(n, vector<ll> (n, -INF));
    dp[0][0] = c[0].first;
    for (int i = 1; i < n; ++i) {
        for (int td = 0; td < i; ++td) {
            for (int t = td; t <= i; ++t) {
                dp[i][t] = max(dp[i][t], dp[i - 1][td] + c[i].first + c[i].second * t);
            }
        }
    }
    ll maxi = -INF;
    for (int i = 0; i < n; ++i) {
        for (int t = 0; t < n; ++t) {
            maxi = max(maxi, dp[i][t]);
        }
    }

    cout << maxi;
}

signed main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    int tt = 1;
    // cin >> tt;
    while (tt--) {
        solve();
        if (tt) {
            cout << '\n';
        }
    }
}