#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define endl '\n'
#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int mod = 998244353;

int add(int a, int b) {
    if (a + b >= mod) {
        return a + b - mod;
    } else {
        return a + b;
    }
}

int sub(int a, int b) {
    if (a < b) {
        return a - b + mod;
    } else {
        return a - b;
    }
}

int mul(int a, int b) {
    return 1ll * a * b % mod;
}

int binpow(int a, int b) {
    int ans = 1;
    while (b > 0) {
        if (b % 2) {
            ans = mul(ans, a);
        }
        a = mul(a, a);
        b /= 2;
    }
    return ans;
}

const int inf = 1e18;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    vector<vector<int>> dp(n, vector<int>(n, -inf));
    int ans = 0;
    dp[0][0] = a[0];
    for (int i = 1; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            for (int k = 0; k <= j; k++) {
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i] + j * b[i]);
            }
        }
    }
    for (int i = 0; i < n; i++) {
        ans = max(ans, *max_element(all(dp[i])));
    }
    cout << ans << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("C:/work/test/input.txt", "r", stdin);
    solve();
    return 0;
}