#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pii pair<int, int>
#define ff first
#define ss second
#define ld long double
#define pb push_back
#define ins insert
#define int ll

mt19937 rnd(1488);

void solve(){
    int n;
    cin >> n;
    vector<pii> c(n);
    for (int i = 0; i < n; i++){
        cin >> c[i].ff >> c[i].ss;
    }
    vector<int> dp(n, -1e9);
    dp[0] = c[0].ff;
    int ans = 0;
    ans = max(ans, c[0].ff);
    for (int i = 1; i < n; i++){
        for (int j = 0; j <= i; j++){
            dp[j] += c[i].ff + j * c[i].ss;
            if (j && dp[j - 1] + c[i].ss > dp[j]){
                dp[j] = dp[j - 1] + c[i].ss;
            }
            ans = max(ans, dp[j]);
        }
    }
    cout << ans << "\n";
}

int32_t main(){
    cin.tie(0)->ios_base::sync_with_stdio(0);
    #ifdef podureman
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif // podureman
    int _ = 1;
    //cin >> _;
    while (_--){
        solve();
    }
}
