
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <unordered_map>
using namespace std;
using ll = long long;
using vll = vector<ll>;
ll mod = 998244353;
ll pow(ll n, ll k) {
    ll ans = 1;
    while (k) {
        if (k & 1) ans = ans * n % mod;
        n = n * n % mod;
        k >>= 1;
    }
    return ans;
}
void solve() {
    ll n;
    cin >> n;
    vll a(n), b(n);
    for (ll i = 0; i < n; ++i) cin >> a[i] >> b[i];
    vll p(n);
    for (ll i = 0; i < n; ++i) cin >> p[i];
    ll ans = 0;
    ll b_sum = 0;
    ll res = -1e18;
    ll pr = 0;
    for (ll i = 0; i < n; ++i) {
        ans += a[i];
        if (b[i] >= 0) {
            b_sum += b[i] * i;
        } else {
            b_sum = 0;
            ll pref = 0;
            for (ll j = 0; j < i; ++j) {
                pref += b[j] * j;
                ll cur = pref;
                for (ll k = j + 1; k <= i; ++k) {
                    cur += b[k] * j;
                }
                b_sum = max(b_sum, cur);
            }
        }
        res = max(res, ans + b_sum);
    }
    cout << res << endl;
}

int main() {
    //freopen("in.txt", "r", stdin);
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t = 1;
    for (int i = 0; i < t; ++i) {
        solve();
    }
    cout << endl;
    return 0;
}
