#include "iostream"
#include "algorithm"
#include "vector"
using namespace std;
#define int long long
#define all(arr) arr.begin(), arr.end()
#define _lg(x) (63 - __builtin_clzll(x))
constexpr int maxn = 100'010;
constexpr int mod = 1'000'000'007;
int dp[maxn]{};
int prev_dp[maxn]{};
void solve() {
    int n; cin >> n;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        int a, b; cin >> a >> b;
        if (!i) {
            prev_dp[0] = a;
            sum = a;
        } else {
            int was = prev_dp[i - 1];
            dp[0] = prev_dp[0] + a;
            prev_dp[0] = dp[0];
            for (int j = 1; j < i; j++) {
                dp[j] = max(a + b * j + prev_dp[j], dp[j - 1]);
                prev_dp[j] = dp[j];
            }
            dp[i] = max(dp[i - 1], was + a + b * i);
            prev_dp[i] = dp[i];
            sum = max(sum, dp[i]);
        }
    }
    cout << sum << '\n';
}

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