// # define _GLIBCXX_DEBUG
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
// #pragma GCC optimize("trapv")
#include <bits/extc++.h>

using namespace std;

template<typename T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag,
    __gnu_pbds::tree_order_statistics_node_update>;

# define int long long
# define all(v) v.begin(),v.end()

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

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

int solve(const vector<pii> &a) {
    vector<int> sumk(a.size());
    sumk[a.size() - 1] = a.back().second;
    for (int i = (int) a.size() - 2; i >= 0; --i) {
        sumk[i] = sumk[i + 1] + a[i].second;
    }
    vector<int> nb(a.size());
    int last = a.size();
    for (int i = a.size() - 1; i >= 0; --i) {
        if (sumk[i] > 0) {
            nb[i] = last;
            last = i;
        } else {
            nb[i] = last;
        }
    }
    int ans = 0;
    int t = 0;
    for (int i = 0; i < a.size(); ++i) {
        if (sumk[i] > 0) {
            ans += a[i].first + a[i].second * i;
            if (i + 1 != a.size() && sumk[i + 1] < 0) {
                int nxt = nb[i + 1];
                for (int j = i + 1; j < nxt; ++j) {
                    ans += a[j].first + a[j].second * i;
                }
                i = nxt - 1;
            }
        } else {
                int nxt = nb[i];
                for (int j = i; j < nxt; ++j) {
                    ans += a[j].first + a[j].second * i;
                }
                i = nxt - 1;

        }

    }
    return ans;
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#elif DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);

    int n;
    cin >> n;
    vector<pii> a(n); // b, k
    for (auto &elem: a)
        cin >> elem.first >> elem.second;
    vector<int> t(n);
    for (auto &elem: t)
        cin >> elem;
    vector<pii> q;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        q.push_back(a[i]);
        ans = max(ans, solve(q));
    }
    cout << ans;
    return 0;
}
