#include <bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define all(a) a.begin(), a.end()
#define db long double
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int, int>
#define vpii vector<pii>
#define vvi vector<vi>

const int N = 1e5;
const int K = 20;
const int INF = 1e18;
const int mod = 998244353;
constexpr char nl = '\n';


void solve() {
    int n;
    cin >> n;
    vi a(n + 1), b(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i] >> b[i];
    }
    vi dp1(n, -INF);
    dp1[0] = a[1];
    int ans = dp1[0];
    vi p(n);
    bool m1 = 1;
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        m1 &= p[i] == -1;
    }
    // if (!m1) return;
    for (int i = 2; i <= n; ++i) {
        vi dp2(n, -INF);
        for (int t = 0; t < i; ++t) {
            for (int k = 0; k <= t; ++k) {
                dp2[t] = max(dp2[t], dp1[k] + a[i] + b[i] * t);
            }
            ans = max(ans, dp2[t]);
        }
        for (int i1 = 0; i1 < n; ++i1) {
            dp1[i1] = dp2[i1];
        }
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
