#pragma GCC optimize("O3")

#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

struct SegTree {
    vector<ll> tree;
    void update(int p, int l, int r, int i, ll x) {
        if (r - l == 1) {
            tree[p] = x;
            return;
        }
        int m = (l + r) / 2;
        if (i < m) {
            update(2 * p + 1, l, m, i, x);
        } else {
            update(2 * p + 2, m, r, i, x);
        }
        tree[p] = max(tree[2 * p + 1], tree[2 * p + 2]);
    }
    ll get(int p, int l, int r, int ql, int qr) {
        if (ql <= l && r <= qr) return tree[p];
        if (l >= qr || r <= ql) return -1e18;
        int m = (l + r) / 2;
        return max(get(2 * p + 1, l, m, ql, qr), get(2 * p + 2, m, r, ql, qr));
    }
    SegTree(int n) {
        tree.resize(4 * n, -1e18);
    }
};

int main() {
    #ifdef LOCAL
    freopen("_test.in", "r", stdin);
    freopen("_test.out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<ll> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];

    SegTree last(n + 1);
    SegTree cur(n + 1);
    ll res = 0;

    last.update(0, 0, n + 1, 0, a[0]);
    for (int i = 1; i < n; i++) {
        for (int t = 0; t <= i; t++) {
            ll mx = last.get(0, 0, n + 1, 0, min(i - 1, t) + 1);
            cur.update(0, 0, n + 1, t, mx + a[i] + b[i] * t);
            // for (int j = 0; j <= min(i - 1, t); j++) {
            //     dp[i][t] = max(dp[i][t], dp[i - 1][j] + a[i] + b[i] * t);
            // }
        }
        res = max(res, last.get(0, 0, n + 1, 0, n + 1));
        last = cur;
        cur = SegTree(n + 1);
    }

    res = max(res, last.get(0, 0, n + 1, 0, n + 1));


    cout << res;
}