#include<bits/stdc++.h>
#define all(p) p.begin(),p.end()
using namespace std;
#define int long long
signed main() {
    int n;
    cin >> n;
    int a[n + 1], b[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
    }
    int p[n + 1];
    int dp[n + 1][n + 1];
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i][j] = -LLONG_MAX / 2;
        }
    }
    dp[0][0] = 0;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int mx = -LLONG_MAX / 2;
        for (int j = 0; j < i; j++) {
            mx = max(mx, dp[i - 1][j]);
            dp[i][j] = max(dp[i][j], mx + j * b[i] + a[i]);
            ans = max(ans, dp[i][j]);
            // cout << dp[i][j] << ' ';
        }
        // cout << endl;
    }
    cout << ans;
}