#include<bits/stdc++.h>
using namespace std;

#define int long long
#define all(x) (x).begin(), (x).end()
using ll = long long;
using ld = long double;
const char nl = '\n';

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

template<typename T>
ostream& operator<< (ostream& out, vector<T> &a) {
    for (auto &el : a) out << el << ' ';
    return out;
}

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

signed main() {
    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;

    /*
    int ans = 0;
    int s = 0;
    for (int i = 0; i < n; i++) {
        if (b[i] <= 0)
            s += a[i];
        else
            s += a[i] + b[i] * i;
        ans = max(ans, s);
    }
    cout << ans;*/


    vector<vector<int>> dp(n, vector<int>(n, LLONG_MIN));
    vector<vector<int>> pref(n, vector<int>(n, LLONG_MIN));
    dp[0][0] = a[0];
    pref[0][0] = dp[0][0];
    int ans = 0;
    for (int i = 1; i < n; i++)
        pref[0][i] = max(pref[0][i - 1], dp[0][i]);

    for (int i = 1; i < n; i++) {
        for (int t = 0; t <= i; t++) {
            for (int j = 0; j <= i - 1; j++) {
                dp[i][t] = max(dp[i][t], dp[i - 1][j] + a[i] + b[i] * t);
                ans = max(ans, dp[i][t]);
            }
        }
        pref[i][0] = dp[i][0];
        for (int j = 1; j < n; j++)
            pref[i][j] = max(pref[i][j - 1], dp[i][j]);
        //cout << pref[i] << nl;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            //cout << i << ' ' << j << ": " << dp[i][j] << nl;
        }
    }
    cout << ans;
}
