#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    int n; cin >> n;
    vector<pair<long long, long long>> g(n);
    for (auto& [x, y] : g) cin >> x >> y;

    vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, -1e18));
    for (int i = 0; i <= n; i++) dp[0][i] = g[0].first;
    for (int i = 1; i < n; i++) {
        long long maxv = dp[i - 1][0];
        for (int j = 0; j <= n; j++) {
            maxv = max(maxv, dp[i - 1][j]);
            if (j <= i) {
                dp[i][j] = maxv + g[i].first + j * 1LL * g[i].second;
            }
        }
    }
    long long maxv = -1e18;
    for (auto& x : dp) {
        for (auto& y : x) {
            maxv = max(maxv, y);
        }
    }
    cout << maxv;
}