#include <bits/stdc++.h>

using namespace std;

const long long MOD = 998244353;

int main()
{
    int n;
    cin >> n;
    vector <pair <long long, long long>> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i].first >> v[i].second;
    }
    vector <int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    vector <vector <long long>> dp(n, vector <long long> (n, 0));
    for (int i = 0; i < n; ++i) {
        dp[0][i] = v[0].first + v[0].second * i;
    }
    for (int i = 1; i < n; ++i) {
        dp[i][0] = dp[i - 1][0] + v[i].first;
    }
    for (int i = 1; i < n; ++i) {
        for (int j = 1; j < n; ++j) {
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1]) + v[i].first + v[i].second * j;
        }
    }
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans;
    return 0;
}
