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

using namespace std;

using ll = long long;
using ld = long double;

const ll INF = 1e18;

struct Pupil {
    ll x;
    ll y;
};

struct SegTree {
    vector<int>tree;

    void Push (int u, int l, int r) {
        if (tree[u] == -1) {
            return;
        }
        tree[2 * u + 1] = tree[u];
        tree[2 * u + 2] = tree[u];
        tree[u] = -1;
    }

    void Update (int u, int l, int r, int left, int right, int x) {
        if (left <= l && r <= right) {
            tree[u] = x;
            return;
        }
        if (right <= l || r <= left) {
            return;
        }
        Push(u, l, r);
        int m = (l + r) >> 1;
        Update(2 * u + 1, l, m, left, right, x);
        Update(2 * u + 2, m, r, left, right, x);
    }

    int Get (int u, int l, int r, int pos) {
        if (r - l == 1) {
            return tree[u];
        }
        Push(u, l, r);
        int m = (l + r) >> 1;
        if (pos < m) {
            return Get(2 * u + 1, l, m, pos);
        }
        else {
            return Get(2 * u + 2, m, r, pos);
        }
    }

    SegTree (int n) {
        tree.resize(4 * n, -1);
    }
};

void Solve () {
    int n;
    cin >> n;
    vector<Pupil>a(n);
    for (auto& [x, y] : a) {
        cin >> x >> y;
    }
    vector<int>p(n);
    for (int& i : p) {
        cin >> i;
    }
    vector<ll>ans(n + 1);
    for (int i = 1; i <= n; ++i) {
        if (a[i - 1].y < 0) {
            ans[i] = ans[i - 1] + a[i - 1].x;
        }
        else {
            ans[i] = ans[i - 1] + a[i - 1].x + (i - 1) * a[i - 1].y;
        }
    }
    ll ansi = 0;
    for (int i = 0; i <= n; ++i) {
        ansi = max(ansi, ans[i]);
    }
    cout << ansi;
}

signed main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        Solve();
    }
}