#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
#define int long long
using ll = long long;
using namespace std;
// #pragma GCC optimize("O3, unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
//  using ordered_set = tree<int, null_type, less<int>, rb_tree_tag,
//  tree_order_statistics_node_update>;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // freopen("in", "r", stdin);
    // freopen("out", "w", stdout);

    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    vector<int> p(n);
    for (auto& x : p) cin >> x;
    int maxn = 0;
    int s = 0;
    for (int i = 0; i < n; ++i) {
        if (b[i] > 0)
            s += a[i] + b[i] * i;
        else
            s += a[i];
        maxn = max(maxn, s);
    }
    cout << maxn << '\n';

    return 0;
}
