#ifndef LOCAL
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<vector>
#pragma GCC optimize("avx2")
#endif

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using i128 = __int128;
using ll = long long;
using ld = long double;

template<typename T>
using orderet_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename T, typename V>
using table = gp_hash_table<T, V>;

const int inf = 2e9 + 7;
const ll INF = 4e18 + 7;
#define int ll

void solve() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
    vector<int> mn(n, -inf), mx(n, inf);
    for (int i = 0; i < n; ++i) {
        mn[i] = 0;
        mx[i] = i;
    }
    for (int i = 1; i <= n; ++i) {
        int p;
        cin >> p;
    }
    vector<vector<int> > dp(n, vector<int>(n, -INF));
    dp[0][0] = a[0];
    for (int i = 1; i < n; ++i) {
        int best = -INF;
        for (int j = 0; j <= mx[i]; ++j) {
            best = max(best, dp[i - 1][j]);
            if (mn[i] <= j) dp[i][j] = best + a[i] + b[i] * j;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans;
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin>>t;
    while (t--) solve();
}
