#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <ctime>
#include <stack>
#include <deque>
#include <queue>
#include <climits>
#include <cmath>
#include <bitset>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define mid (l + r) / 2
#define int long long

constexpr int maxn = 5005;
int a[maxn];
int b[maxn];
int dp[maxn][maxn];

void solve() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    int best = 0;
    for (int i = 0; i < n + 3; i++) {
        for (int j = 0; j < n + 3; j++) {
            dp[i][j] = INT_MIN;
        }
    }
    dp[0][0] = a[0];
    for (int i = 1; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            for (int e = 0; e <= j; e++) {
                dp[i][j] = max(dp[i][j], dp[i - 1][e] + a[i] + b[i] * j);
                best = max(best, dp[i][j]);
                continue;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        int X; cin >> X;
    }
    cout << best << '\n';
    return;
}

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