#include <bits/stdc++.h>
using namespace std;
int 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, 0));
    for (int i = 0; i < 1; i++) dp[1][i] = g[0].first;
    for (int i = 2; i <= n; i++) {
        long long maxv = -1e18;
        for (int j = 0; j <= n; j++) {
            if (j < i) {
                maxv = max(maxv, dp[i - 1][j])
                dp[i][j] = maxv + g[i - 1].first + j * g[i - 1].second;
                maxv = max(maxv, dp[i - 1][j]);
            } else {
                dp[i][j] = dp[i][i - 1];
            }
        }
    }
    long long maxv = dp[1][0];
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            maxv = max(maxv, dp[i][j]);
        }
    }
    cout << maxv;
}