#include <bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;
typedef long long ll;

const ll mod = 998244353;

void solve() {
    int n;
    ll now = 0, mx = 0;
    cin >> n;
    int t = 0;
    vector<int> a(n), b(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        if (b[i] >= 0) {
            now += a[i] + b[i] * i;
            t = i;
        } else {
            now += a[i] + b[i] * t;
        }
        mx = max(mx, now);
    }
    bool f = 1;
    vector<int> p(n);
    for (auto& i : p) {
        cin >> i;
        if (i != -1)
            f = 0;
    }
    now = 0;
    ll mx1 = 0;
    ll timer = 0;
    for (int i = 0; i < n; ++i) {
        if (rand() % 3)
            timer++;
        now += a[i] + b[i] * timer;
        mx1 = max(mx1, now);
    }
    if (f)
        cout << max(mx, mx1) << '\n';
    else
        cout << mx1 << '\n';
}

int main() { 
    srand(0);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}
