#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define all(a) (a).begin(), (a).end()

using namespace std;
using namespace __gnu_pbds;

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

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

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin >> t;
    while (t--) solve();
}

#define int ll

int mod = 998244353;

struct Mint {
    int x;

    Mint() :x(0) {}
    Mint(int x) : x(x) {}
};

Mint operator+(Mint a, Mint b) {
    int c = a.x + b.x;
    return c < mod ? c : c - mod;
}

Mint operator-(Mint a, Mint b) {
    int c = a.x - b.x;
    return c < 0 ? c + mod : c;
}

Mint operator*(Mint a, Mint b) {
    return a.x * b.x % mod;
}

Mint powm(Mint a, int n) {
    if (n == 0) return 1;
    Mint t = powm(a, n >> 1);
    t = t * t;
    return n & 1 ? t * a : t;
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), p(n);
    for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
    for (auto& x : p) cin >> x;
    int mn = max(0ll, *max_element(all(p)));
    vector dp(n, vector<int>(n));
    vector<int> pa(n + 1, 0), pb(n + 1, 0);
    for (int i = 0; i < n; ++i) {
        pa[i + 1] = pa[i] + a[i];
        pb[i + 1] = pb[i] + b[i];
    }
    auto f = [&] (int t, int i, int j) {
        return pa[i + 1] - pa[j] + t * (pb[i + 1] - pb[j]);
    };
    for (int t = 0; t < n; ++t) {
        for (int i = t; i < n; ++i) {
            for (int j = 0; j <= i; ++j) {
                dp[t][i] = (t >= 1 ? dp[t - 1][j] : 0) + f(t, i, j);
            }
        }
    }
    ll ans = -1e18;
    for (int t = mn; t < n; ++t)
        for (int i = 0; i < n; ++i)
            ans = max(ans, dp[t][i]);
    cout << ans << '\n';
}