#pragma GCC optimize("O3")

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

#define int long long
#define db long double
#define MX LLONG_MAX
#define MN LLONG_MIN
#define gcd __gcd
#define lcm(a, b) (a / gcd(a, b) * b)

using namespace std;
using namespace __gnu_pbds;
using ll = long long;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;
    cin >> n;

    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cin >> b[i];
    }

    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];

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

    cout << ans;
}
