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


#define int long long
#define line cout << "\n"
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define sz(a) (int) a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pii pair<int, int>

typedef string str;
typedef long long ll;
typedef long double ld;


void solve() {
    int n;
    cin >> n;
    vector<pii> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i].first >> a[i].second;
    }
    vector<int> dp(n + 1);
    vector<int> p(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int add = 0;
    int ans = 0;
    int add2 = 0;
    for (int j = 1; j <= n; j++) {
        if (a[j].second > 0) {
            for (int i = 1; i <= j; i++) {
                dp[i] += add * (i - 1) + add2;
            }
            add = add2 = 0;
            int ma = -1e18;
            for (int i = 1; i <= j; i++) {
                ma = max(ma, dp[i]);
                dp[i] = ma + a[j].first + a[j].second * (i - 1);
                ans = max(ans, dp[i]);
            }
        } else {
            add2 += a[j].first;
            add += a[j].second;
            for (int i = 1; i <= min(j, 100ll); i++) {
                ans = max(ans, dp[i] + add * (i - 1) + add2);
            }
        }
    }
    cout << ans; line;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);


#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}