#include <bits/stdc++.h>

#define all(v) v.begin(), v.end()
#define len(v) (int)v.size()

using namespace std;
using ll = long long;
using ld = long double;

void solve()
{
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    vector<int> p(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < n; ++i)
    {
        cin >> p[i];
    }
    ll ans = 0;
    ll cur = 0;
    int lt = 0;
    for (int k = 0; k < n; ++k)
    {
        if (p[k] == -1)
        {
            lt = k;
            cur += a[k] + b[k] * lt;
        }
        ans = max(ans, cur);
    }
    cout << ans;
}

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    //cin >> t;

    while (t--)
    {
        solve();
        cout << '\n';
    }
    return 0;
}
