#include <bits/stdc++.h>
#define int long long

using namespace std;

struct pr {
    int k = 0, b = -1e18;
    long long operator ()(int x) {
        return k * x + b;
    }
};

struct Node {
    Node *l = 0, *r = 0;
    pr a;
    Node (pr _a) {
        a = _a;
    }
};

void upd(Node *v, int l, int r, pr ln) {
    if (l == r - 1) {
        if (ln(l) > (v -> a)(l)) swap(ln, v -> a);
        return;
    }
    int m = (l + r) / 2;
    if (ln.k > (v -> a).k) swap(ln, v -> a);
    if (ln(m) > (v -> a)(m)) {
        swap(ln, v -> a);
        if (!(v -> r)) v -> r = new Node(ln);
        else upd(v -> r, m, r, ln);
    } else {
        if (!(v -> l)) v -> l = new Node(ln);
        else upd(v -> l, l, m, ln);
    }
}

int get(Node *v, int l, int r, int x) {
    if (!v) return -1e18;
    int m = (l + r) / 2;
    if (x < m) return max((v -> a)(x), get(v -> l, l, m, x));
    return max((v -> a)(x), get(v -> r, m, r, x));
}

Node* root;

signed main() {
    int n;
    cin >> n;
    vector <pair <int, int>> arr(n);
    vector <int> prefa(n + 1), prefb(n + 1);
    pr clr;
    root = new Node(clr);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i].first >> arr[i].second;
        prefa[i + 1] = prefa[i] + arr[i].first;
        prefb[i + 1] = prefb[i] + arr[i].second;
    }
    for (int i = 0; i < n; ++i) {
        int p;
        cin >> p;
    }
    vector <int> dp(n, -1e18);
    dp[0] = arr[0].first;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (arr[i].second <= 0 && i != 0) continue;
        root = new Node(clr);
        for (int j = i; j < n; ++j) {
            if (j != i && arr[j].second > 0) break;
            pr ln;
            ln.k = prefb[j + 1];
            ln.b = prefa[j + 1];
            upd(root, 0, n, ln);
        }
        if (i != 0) {
            int maxx = -1e18;
            vector <int> dp1(n, -1e18);
            for (int c = 0; c <= i; ++c) {
                maxx = max(maxx, dp[c]);
                dp1[c] = maxx + arr[i].first + arr[i].second * c;
            }
            swap(dp1, dp);
        }
        for (int c = 0; c <= i; ++c) {
            ans = max(ans, dp[c] + get(root, 0, n, c) - prefa[i + 1] - prefb[i + 1] * c);
        }
    }
    cout << ans << endl;
    return 0;
}
