#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using lll = __int128;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const int inf = 0x3f3f3f3f;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(x) 67
#endif
const ll mod = 998'244'353;
const lll INF = 2e20;

struct line {
    lll k = 0, b = -INF;
    lll at(ll p) {
        return k * p + b;
    }
};
struct node {
    line ln;
    int l = -1, r = -1;
};
vector<node> li(1);
void add(line now, int x, int lx, int rx) {
    if (li[x].ln.k == 0 && li[x].ln.b == -INF) {
        li[x].ln = now;
        return;
    }
    int mid = (lx + rx) / 2;
    if (now.at(mid) > li[x].ln.at(mid)) {
        swap(now, li[x].ln);
    }
    if (rx - lx == 1)return;
    if (now.k < li[x].ln.k) {
        if (li[x].l == -1) {
            li[x].l = (int)li.size();
            li.emplace_back();
        }
        add(now, li[x].l, lx, mid);
    } else {
        if (li[x].r == -1) {
            li[x].r = (int)li.size();
            li.emplace_back();
        }
        add(now, li[x].r, mid, rx);
    }
}
lll get(ll p, int x, int lx, int rx) {
    if (x == -1)return -INF;
    lll ans = li[x].ln.at(p);
    int mid = (lx + rx) / 2;
    if (p < mid) {
        ans = max(ans, get(p, li[x].l, lx, mid));
    } else {
        ans = max(ans, get(p, li[x].r, mid, rx));
    }
    return ans;
}
void solve() {
    int n;
    cin >> n;
    vector<pll> c(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i].first >> c[i].second;
    }
    vector<int> p(n);
    for (int &i: p) {
        cin >> i;
        assert(i == -1);
    }
    vector<ll> pra(n + 1), prb(n + 1);
    for (int i = 0; i < n; ++i) {
        pra[i + 1] = pra[i] + c[i].first;
        prb[i + 1] = prb[i] + c[i].second;
    }
    vector<lll> dp(n + 1, 0);
    dp[n] = 0;
    for (ll i = n - 1; i >= 0; --i) {
        line ln = {prb[i + 1], pra[i + 1] + dp[i + 1]};
        add(ln, 0, 0, (1 << 21));
        lll var = get(i, 0, 0, (1 << 21)) - pra[i] - prb[i] * i;
        if (var < 0) {
            dp[i] = 0;
        } else {
            dp[i] = var;
        }
    }
    vector<int> ans;
    lll v = dp[0];
    if (v == 0) {
        cout << 0;
        return;
    }
    while (v > 0) {
        ans.push_back(v % 10);
        v /= 10;
    }
    reverse(all(ans));
    for (auto v : ans)cout << v;
}

signed main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    int tt = 1;
    // cin >> tt;
    while (tt--) {
        solve();
        if (tt) {
            cout << '\n';
        }
    }
}
