// # 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());

inline int calc(int mid, const vector<pii> &a) {
    int now_ans = 0;
    for (int i = 0; i <= mid; ++i) {
        now_ans += a[i].first;
    }
    int add = 0;
    int best = now_ans;
    for (int i = mid + 1; i < a.size(); ++i) {
        add = i * a[i].second + a[i].first;
        now_ans += add;
        best = max(best, now_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;
    int l = 0, r = n + 1;
    int ans = 0;
    while (r - l != 1) {
        int mid1 = (r - l) / 3 + l;
        int mid2 = (r - l) / 3 * 2 + l;
        int ans1 = calc(mid1, a);
        int ans2 = calc(mid2, a);
        if (ans1 < ans2) {
            l = mid1;
        } else {
            r = mid2;
        }
    }
    for (int i = l; i < r; ++i) {
        ans = max(ans, calc(i, a));
    }
    cout << ans;
    return 0;
}
