#include <iostream>
#include <vector>


#define maxn 1000005
#define maxlog 21
#define X first
#define Y second
#define control std::cout<<"passed"<<"\n";

typedef long long ll;
typedef long double ld;
typedef std::pair <int , int> pii;
typedef std::pair <ll , ll> pll;


const ll inf = 4e18;


int n;
ll a[maxn] , b[maxn] , p[maxn];




void read()
{
    std::cin >> n;
    for (int i = 1; i <= n; i++)
        std::cin >> a[i] >> b[i];
    for (int i = 1; i <= n; i++)
        std::cin >> p[i];

    ll sum = 0;
    ll ans = 0;

    ll maxx = 0;

    for (int i = 1; i <= n; i++)
    {
        //sum += a[i] + b[i] * (ll)(i - 1);

        if (b[i] <= 0)
            sum += a[i] + maxx * b[i];
        else
            sum += a[i] + b[i] * std::max((ll)(i - 1) , maxx);

        if (p[i] != -1)
            maxx = std::max(maxx , (ll)i);

        ans = std::max(ans , sum);
    }

    std::cout << ans << "\n";
}






int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int tests = 1;
    //std::cin >> tests;
    while (tests--)
    {
        read();
    }

    return 0;
}