#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cassert>
#include <random>
#define rep(n) for (int (i) = 0; (i) < (n); (i)++)
#define all(n) (n).begin(), (n).end()
#define rall(n) (n).rbegin(), (n).rend()
#define mp make_pair
#define ll long long
#define ld long double
//#define int long long
//#define FILE

using namespace std;

const int mod = 998244353;
const ll inf = 4e18;

ll calc(pair<ll, ll> p, int x) {
    return p.first + p.second * x;
}

void solve() {
    int n; cin >> n;
    vector<pair<ll, ll>> A(n);
    rep(n) {
        cin >> A[i].first >> A[i].second;
    }
    vector<vector<ll>> dp(n, vector<ll> (n, -inf));
    dp[0][0] = A[0].first;
    ll ans = A[0].first;
    for (int i = 1; i < n; i++) {
        for (int t = 0; t <= i; t++) {
            for (int t_prv = t; t_prv >= 0; t_prv--) {
                dp[i][t] = max(dp[i][t], dp[i - 1][t_prv] + calc(A[i], t));
                ans = max(ans, dp[i][t]);
            }
        }
    }
    cout << max(0ll, ans) << '\n';
}

int main() {
    //ios_base::sync_with_stdio(false);
    //cin.tie(nullptr);
#ifdef FILE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "W", stdout);
#endif
    int tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }
}
/*
4
-6 -1
-5 14
0 10
-30 2
-1 -1 -1 -1
*/