#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(x) x.begin(), x.end()

const int INF = 1e18;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
    }
    int mx = 0, sum = 0, last = 0;
    int dp[n][n];
    dp[0][0] = a[0];
    int ans = -1;

    for (int i = 1; i < n; i++) {
        for (int last = 0; last < i; last++) {
            for (int t = last; t < i + 1; t++) {
                dp[i][t] = dp[i - 1][last] + a[i] + b[i] * t;
                ans = max(ans, dp[i][t]);
            }
        }
    }

    cout << max(0LL, ans);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}