#include <bits/stdc++.h>
using ll = long long;
#define int ll

using namespace std;
const int mod = 998244353;
struct Mint {
    int val;
    Mint() {
        val = 0;
    }
    Mint(int x) {
        x %= mod;
        if (x < 0) x += mod;
        val = x;
    }
};
Mint operator+=(Mint& a, Mint b) {
    a.val += b.val;
    if (a.val >= mod) a.val -= mod;
    return a;
}
Mint operator-=(Mint& a, Mint b) {
    a.val -= b.val;
    if (a.val < 0) a.val += mod;
    return a;
}
Mint operator+(Mint a, Mint b) {
    a += b;
    return a;
}
Mint operator-(Mint a, Mint b) {
    a -= b;
    return a;
}
Mint operator*=(Mint& a, Mint b) {
    a.val = 1ll * a.val * b.val % mod;
    return a;
}
Mint operator*(Mint a, Mint b) {
    a *= b;
    return a;
}
Mint binpow(Mint x, int p) {
    if (p == 0) return 1;
    if (p == 1) return x;
    if (p % 2 == 0) {
        return binpow(x * x, p / 2);
    }
    return x * binpow(x, p - 1);
}
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> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    vector<vector<int>> dp(n, vector<int>(n, -1e18));
    dp[0][0] = 0;
    vector<vector<int>> prefma(n, vector<int>(n));
    prefma[0][0] = 0;
    for (int i = 1; i < n; i++) {
        for (int t = 0; t < i + 1; t++) {
            dp[i][t] = prefma[i - 1][t] + b[i] * t;
            
        }
        prefma[i][0] = dp[i][0];
        for (int t = 1; t < n; t++) prefma[i][t] = max(prefma[i][t - 1], dp[i][t]);
    }
    int res = -1e18;
    int suma = 0;
    for (int k = 0; k < n; k++) {
        suma += a[k];
        res = max(res, suma + prefma[k][n - 1]);
    }
    cout << res << "\n";

}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t --> 0) solve();
}