#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
//#define DEBUG

using namespace std;

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

int n;
vector<pair<ll, ll>> A;

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

ll solve() {
    vector<ll> dp(n, -inf);
    dp[0] = A[0].first;
    vector<ll> pref(n, dp[0]);
    ll ans = dp[0];
    for (int i = 1; i < n; i++) {
        vector<ll> dp2(n, -inf);
        for (int t = 0; t <= i; t++) {
            dp2[t] = pref[t] + calc(A[i], t);
            ans = max(ans, dp2[t]);
        }
        dp = dp2;
        pref[0] = dp[0];
        for (int j = 1; j < n; j++) {
            pref[j] = max(pref[j - 1], dp[j]);
        }
    }
    return max(0ll, ans);
}

ll solve2() {
    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]);
            }
        }
    }
    return max(0ll, ans);
}

int main() {
    //ios_base::sync_with_stdio(false);
    //cin.tie(nullptr);
#ifdef FILE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "W", stdout);
#endif
#ifndef DEBUG
    int tt = 1;
    //cin >> tt;
    while (tt--) {
        cin >> n;
        A.resize(n);
        rep(n) cin >> A[i].first >> A[i].second;
        ll ans = solve();
        cout << ans << '\n';
    }
#else
    int tt = 1;
    cin >> tt;
    int cnt = 1;
    while (tt--) {
        n = rand() % 3 + 1;
        A.resize(n);
        rep(n) {
            A[i].first = (ll) rand() % 10 - 5;
            A[i].second = (ll) rand() % 10 - 5;
        }
        ll ans1 = solve();
        ll ans2 = solve2();
        assert(ans1 == ans2);
        A.clear();
        cout << cnt++ << endl;
    }
#endif
}
/*
4
-6 -1
-5 14
0 10
-30 2
-1 -1 -1 -1
*/