#include <bits/stdc++.h>
#define int long long
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define em emplace_back

using namespace std;
template<class C>
using vec = vector<C>;
using vi = vector<int>;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifdef LOCAL
    freopen("input", "r", stdin);
#endif
    int n;
    cin >> n;
    vi a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    vi p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        assert(p[i] == -1);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i == 2) {
            cout<<"";
        }
        int suma = 0;
        for (int j = 0; j <= i; j++) {
            suma += a[j];
        }
        int add = 0;
        int sum = 0;
        for (int j = i; j >= 0; j--) {
            sum += b[j];
            if (sum >= 0) {
                add += j * sum;
                sum = 0;
            }
        }
        ans = max(ans, suma + add);
    }
    cout << ans << '\n';
}