#include <bits/stdc++.h>

using namespace std;

const int MOD = 998244353;

#define int long long

int powmod(int v, int mod) {
    int cr = 1;
    while (mod) {
        if (mod & 1) cr *= v;
        v *= v;
        cr %= MOD; v %= MOD; mod >>= 1;
    }
    return cr % MOD;
}

int32_t main() {
    int n; cin >> n;
    vector<vector<int>> dp(n, vector<int>(n, -1e18));
    vector<pair<int, int>> a(n); for (auto &i : a) cin >> i.first >> i.second;

    vector<int> p(n); for (auto &i : p) cin >> i;
    vector<int> f(n), s(n); for (int i = 0; i < n; i++) f[i] = (i ? f[i - 1] : 0) + a[i].first;
    for (int i = 0; i< n; i++) s[i] = (i ? s[i - 1] : 0) + a[i].second;
    dp[0][0] = a[0].first;
    for (int i = 1; i < n; i++) {
        int mn = -1e18;
        for (int j = 0; j <= i; j++) mn = max(mn, dp[i - 1][j]), dp[i][j] = max(dp[i][j], mn + a[i].first + a[i].second * j);
    }
    int rs = dp[0][0];
    for (auto &i : dp) for (auto &j : i) rs = max(rs, j);
    cout << rs;
    return 0;
}