#include "bits/stdc++.h"

using namespace std;

template<typename T>
istream &operator>>(istream &is, vector<T> &a) {
      for (T &elem: a) is >> elem;
      return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
      for (T elem: a) os << elem << ' ';
      return (os << '\n');
}

#define int long long

signed main() {
#ifdef LOCAL
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
#else
      cin.tie(nullptr);
      ios_base::sync_with_stdio(false);
#endif
      int n;
      cin >> n;
      vector<int> a(n), b(n);
      for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];

      vector dp(n, vector<int>(n, -1e18));
      vector p(n, vector<int> (n, -1e18));
      dp[0][0] = a[0];
      for (int i = 1; i < n; ++i) {
            for (int val = 0; val <= i; ++val) {
                  dp[i][val] = p[i - 1][val] + a[i] * b[i] * val;
//                  for (int last = 0; last <= val; ++last) {
//                        dp[i][val] = max(dp[i][val], dp[i - 1][last] + a[i] + b[i] * val);
//                  }
                  if (val) p[i][val] = p[i][val] - 1;
                  p[i][val] = max(p[i][val], dp[i][val]);
            }
      }

      int res = 0;
      for (int i = 0; i < n; ++i) {
            for (int val = 0; val < n; ++val) {
                  res = max(res, dp[i][val]);
            }
      }
      cout << res << '\n';

}