#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<pll> 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<ll> dp(n + 1, -INF);
    dp[n] = 0;
    for (ll i = n - 1; i >= 0; --i) {
        ll suma = 0;
        ll sumb = 0;
        dp[i] = max(dp[i], c[i].first + c[i].second * i);
        for (ll j = i; j < n; ++j) {
            suma += c[j].first;
            sumb += c[j].second;
            dp[i] = max(dp[i], dp[j + 1] + suma + sumb * i);
        }
    }
    debug(dp);
    cout << dp[0];
}

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';
        }
    }
}