#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const int INF = 1e18 + 500;

int get(int l, int r, vector<int> &pref) {
    if (l == 0) return pref[r];
    return pref[r] - pref[l - 1];
}
void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
    vector<int> p(n);
    for (int i = 0; i < n; ++i) cin >> p[i];
    vector<int> dp(n, -INF);
    vector<int> prefa(n, 0);
    prefa[0] = a[0];
    for (int i = 1; i < n; ++i) prefa[i] = prefa[i - 1] + a[i];
    vector<int> prefb(n, 0);
    prefb[0] = b[0];
    for (int i = 1; i < n; ++i) prefb[i] = prefb[i - 1] + b[i];
    dp[0] = a[0];
    for (int i = 0; i < n; ++i) {
        dp[i] = max(dp[i], get(0, i, prefa) + get(0, i, prefb) * 0);
        for (int j = 0; j < i; ++j) {
            int t = j + 1;
            dp[i] = max(dp[i], dp[j] + get(j + 1, i, prefa) + get(j + 1, i, prefb) * t);
        }
    }
    //for (auto i:dp) cout << i << ' ';
    //cout << endl;
    int mx = 0;
    for (auto i:dp) mx = max(mx, i);
    cout << mx << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    int t = 1;
    while (t--) solve();
}
