#pragma GCC optimize("O3")
#include <vector>

#pragma GCC target("avx2")
#include <algorithm>
#include <numeric>
#include <iostream>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <set>
#include <map>

using namespace std;

#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define pld pair<ld, ld>

#define vll vector<ll>
#define vvll vector<vll>
#define vvvll vector<vvll>
#define vvvvll vector<vvvll>

#define vld vector<ld>
#define vvld vector<vld>
#define vvvld vector<vvld>
#define vvvvld vector<vvvld>

#define vpll vector<pll>
#define vvpll vector<vpll>
#define vvvpll vector<vvpll>
#define vvvvpll vector<vvvpll>

#define vpld vector<pld>
#define vvpld vector<vpld>
#define vvvpld vector<vvpld>
#define vvvvpld vector<vvvpld>

#define forlr(i, l, r) for(ll i = (l); i < (r); ++i)
#define forn(i, n) forlr(i, 0, n)
#define forin(x, v) for(auto& x : v)

#define all(v) v.begin(), v.end()
#define pb emplace_back

template <class T>
istream& operator>>(istream& in, vector<T>& v) {
	forin(x, v)
		in >> x;
	return in;
}

template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
	forin(x, v)
		out << x << ' ';
	return out;
}

void main0() {
	ll n;
	cin >> n;
	vll a(n), b(n);
	forn(i, n)
		cin >> a[i] >> b[i];

	vvll dp(n + 1, vll(n, -1e18)); // j = t[i]
	dp[0] = vll(n);
	forlr(i, 1, n + 1) {
		forn(j, i) {
			forn(p, j + 1) {
				dp[i][j] = max(dp[i][j], dp[i - 1][p] + a[i - 1] + j * b[i - 1]);
			}
		}
	}

	ll ans = 0;
	forin(v, dp)
		forin(x, v)
		ans = max(ans, x);
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

#ifdef _LOCAL
	while (1)
#endif // _LOCAL
	{
		ll t = 1;
		//cin >> t;
		while (t--) {
			main0();
			cout << endl;
		}
	};
}
