#include using namespace std; long long dp[5001][5001]; const long long INF = 1LL << 60; template inline bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector a(n), b(n); for(int i = 0; i < n; i++){ cin >> a[i] >> b[i]; } reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); for(int i = 0; i <= n; i++){ for(int j = 0; j <= n; j++){ dp[i][j] = -INF; } } dp[0][0] = 0; for(int i = 0; i < n; i++){ for(int j = 0; j <= i; j++){ chmax(dp[i + 1][j], dp[i][j] + a[i] * j); chmax(dp[i + 1][j + 1], dp[i][j] + b[i]); } } long long ans = -INF; for(int i = 0; i <= n; i++){ chmax(ans, dp[n][i]); } cout << ans << endl; return 0; }