#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>

#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;


ll n;
ll a[maxn] , b[maxn] , p[maxn];
ll st[maxn];
ll l[maxn] , t[maxn];
__int128 prefa[maxn] , prefb[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 minn = 0;
    for (int i = 1; i <= n; i++)
        if (p[i] != -1)
            minn = std::max(minn , p[i]);

    for (int i = 1; i <= n; i++)
        prefa[i] = prefa[i - 1] + (__int128)a[i] + (__int128)b[i] * (__int128)(i - 1);

    __int128 ans = -inf;
    if (minn == 0)
        ans = 0;
    for (int i = std::max(1LL , minn); i <= n; i++)
        ans = std::max(ans , prefa[i]);

    std::vector <int> rr;
    int ss = 1;
    if (ans < 0)
        ss = -1;
    while (ans != 0)
    {
        rr.push_back(ans % 10);
        ans /= 10;
    }
    
    if (ss == -1)
        std::cout << "-";
    
    std::reverse(rr.begin() , rr.end());
    for (auto& e : rr)
        std::cout << e;
    std::cout << "\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;
}