#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>

using namespace std;
using ll = long long;
using ld = long double;

#define int ll

const int INF = 1e18;

struct Node {
    int a, b;
};

signed main() {
    int n;
    cin >> n;

    vector<Node> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].a >> a[i].b;
    }

    vector<vector<int>> dp(n + 1, vector<int> (n + 1, -INF));
    dp[0][0] = 0;
    int res = 0;
    for (int i = 0; i < n; ++i) {
        int nowm = -INF;
        for (int t = 0; t <= i; ++t) {
            nowm = max(nowm, dp[i][t]);
            dp[i + 1][t] = nowm + a[i].a + a[i].b * t;
            res = max(res, dp[i + 1][t]);
        }
    }

    cout << res;
}