 // hello, it is a very good problem
#include <bits/stdc++.h>

using namespace std;

main() {
    long long n;
    cin >> n;
    vector<long long> a(n), b(n);
    for (long long i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    vector<tuple<long long, long long, long long>> st = {{0, -1, 0}};
    long long ans = 0, sum = 0;
    for (long long i = 0; i < n; ++i) {
        sum += a[i] + i * b[i];
        get<2>(st.back()) += b[i];
        while (st.size() > 0 && get<0>(st.back()) + get<2>(st.back()) <= 0) {
            if (st.size() >= 2) {
                long long er = get<2>(st.back());
                long long j = (long long)st.size() - 2;
                sum -= (get<0>(st.back()) + get<2>(st.back())) * (get<1>(st.back()) - get<1>(st[j]));
                st.pop_back();
                get<2>(st.back()) += er;
            } else {
                sum -= (get<0>(st.back()) + get<2>(st.back())) * (get<1>(st.back()) + 1);
                st.pop_back();
            }
        }
        st.push_back({0, i, 0});
        ans = max(ans, sum);
    }
    cout << ans << '\n';
}
