//#define _GLIBCXX_DEBUG 1
//#pragma GCC optimize ("03, unroll-seen")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll inf = 1e18, mod = 998244353;


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    //ifstream cin ("input.txt");
    //ofstream cout ("output.txt");
    int n;
    cin >> n;
    vector<pair<ll, ll>> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i].first >> a[i].second;
    vector<vector<ll>> dp(n, vector<ll> (n));
    for (int i = 0; i <= 1; i++)
        dp[0][i] = a[0].first+i*a[0].second;
    ll ans = max(dp[0][0], dp[0][1]);
    for (int i = 1; i < n; i++) {
        ll mx = LLONG_MIN;
        for (int j = 0; j <= i; j++) {
            mx = max(mx, dp[i-1][j]);
            dp[i][j] = mx+a[i].first+a[i].second*j;
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans;
}