#include <bits/stdc++.h>

using namespace std;

const long long INF = 1e18 + 5;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<long long> a(n), b(n);
    for (long long i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    vector<vector<long long>> dp(n, vector<long long> (n, -INF));
    dp[0][0] = a[0];
    for (int i = 1; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            for (int k = 0; k <= j; k++) {
                dp[i][j] = max(dp[i][j], dp[i - 1][k]);
            }
            dp[i][j] += a[i];
            dp[i][j] += b[i] * j;
        }
    }
    long long mx = 0;
    for (int i = 0; i < n; i++) {
        mx = max(mx, (*max_element(dp[i].begin(), dp[i].end())));
    }
    cout << mx;
}
