#ifndef local
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
using str = string;
using hashmap = gp_hash_table<ll,ll>;
using hashset = gp_hash_table<ll, null_type>;
using ordset = tree<ll,null_type, less<>,rb_tree_tag, tree_order_statistics_node_update>;


auto SD = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rnd(SD);
const ll mod = 998244353;
ll add(ll a, ll b) {
    return((a%mod)+(b%mod))%mod;
}
ll mult(ll a, ll b) {
    return((a%mod)*(b%mod))%mod;
}
ll pow_(ll e, ll n) {
    ll i = 1;
    while (n) {
        if ((n&1)) {
            i = mult(i, e);
        }e=mult(e,e);
        n >>= 1;
    }return i;
}

ll cnt_sum(vector<ll>p) {
    ll ans = 0;
    for (int i= 0; i < p.size(); i++) {
        ans =add(ans, pow_(p[i],i+1));
    }return ans;
}
vector<ll> p(vector<ll>o) {
    vector<ll> ans(o.size());
    for (int i = 0; i < o.size(); i++) {
        ans[i] = o.size()+1-o[i];
    }return ans;
}vector<ll> inv(vector<ll>o) {
    vector<ll> ans(o.size());
    for (int i = 0; i < o.size(); i++) {
        ans[o[i]-1]=i+1;
    }return ans;
}
vector<ll> rev(vector<ll>o) {
    vector<ll> ans = o;reverse(ans.begin(), ans.end());
    return ans;
}
const ll inf = 1e18;
void sol() {
    ll  n;
    cin>>n;
    vector<pll> t;
    for (int i =0; i <n ;i++) {
        ll ai, bi;
        cin>>ai>>bi;
        t.emplace_back(ai, bi);
    }
    vector<vector<ll>> dp(n+1, vector<ll>(n,-inf));
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
       // dp[i] = max(dp[i-1],dp[i]);
        ll Ans= -inf;
        for (int tj = i-1; tj < i; tj++) {
             for (int j = max(0,tj-1);j<=tj;j++) {
                 Ans=max(Ans, dp[i-1][j]);
             }
             dp[i][tj]= max(dp[i][tj],Ans+tj*t[i-1].second+t[i-1].first);

        }
    }
    ll res = 0;
    for (int i =1; i <= n; i++) {
        for (int time = 0; time < i; time++) {
            res=max(res, dp[i][time]);
        }
    }
    cout<<res;

}
signed main() {
#ifdef local
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    cout<<fixed<<setprecision(19);
    ll t1 = 1;
    //cin>>t1
    while (t1--) {
        sol();
    }
}