#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimise("O3, unroll-loops")
#pragma GCC target("avx,avx2,popcnt")

#define int long long
#define pb push_back
#define all(a) a.begin(), a.end()
#define db long double
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int, int>
#define vpii vector<pii>
#define vvi vector<vi>

const int N = 1e5;
const int K = 20;
const int INF = 1e18;
const int mod = 998244353;
constexpr char nl = '\n';

// lando norris 2025 world champion

int bin_pow(int a, int p) {
    if (p < 0) {
        return 0;
    }
    if (p == 0) {
        return 1;
    }
    __int128 res = 1;
    int pw = a;
    while (p) {
        if (p & 1) {
            res = res * pw % mod;
        }
        pw = pw * pw % mod;
        p >>= 1;
    }
    res %= mod;
    return res;
}


vi g[N];
int h[N];
int binup[N][K];

void dfs(int v, int p = -1) {
    if (p != -1) {
        h[v] = h[p] + 1;
        binup[v][0] = p;
    }
    for (int k = 1; k < K; ++k) {
        binup[v][k] = binup[binup[v][k - 1]][k - 1];
    }
    for (auto u: g[v]) {
        if (u != p) {
            dfs(u, v);
        }
    }
}

int lca(int v, int u) {
    if (h[u] > h[v]) swap(u, v);
    for (int k = K - 1; k >= 0; --k) {
        if (h[v] >= h[u] + (1 << k)) {
            v = binup[v][k];
        }
    }
    if (u == v) return u;

    for (int k = K - 1; k >= 0; --k) {
        if (binup[v][k] != binup[u][k]) {
            v = binup[v][k];
            u = binup[u][k];
        }
    }
    return binup[u][0];
}

void solve() {
    int n;
    cin >> n;
    vi a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    vi dp1(n, -INF);
    dp1[0] = a[0];
    int ans = dp1[0];
    for (int i = 1; i < n; ++i) {
        vi dp2(n, -INF);
        for (int j = 0; j <= i; ++j) {
            if (j) {
                dp2[j] = max(dp1[j], dp1[j - 1]) + a[i] + b[i] * j;
            } else {
                dp2[j] = dp1[j] + a[i];
            }
            ans = max(ans, dp2[j]);
        }
        dp1 = dp2;
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
