#ifndef LOCAL
#pragma GCC optimize("O3,unroll-loops")
#endif

#include <bits/extc++.h>

using namespace std;

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

int32_t main() {
#ifndef LOCAL
    cin.tie(nullptr), ios_base::sync_with_stdio(false);
#endif
    int n;
    cin >> n;
    vector <int> a(n + 1), b(n + 1), p(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
    for (int i = 1; i <= n; i++) cin >> p[i];
    vector <vector <int>> dp(n + 1, vector <int> (n, -1e15));
    int ans = 0;
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        int mx = dp[i - 1][0];
        for (int j = 0; j < i; j++) {
            if (j != i - 1) mx = max(mx, dp[i - 1][j]);
            dp[i][j] = a[i] + b[i] * j + mx;
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans;
    return 0;
}
