// template.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
// #define int long long

using namespace std;
using ll = long long;
using ld = long double;

const int MOD = 998244353;

int modpow(int a, int b)
{
    if (b == 0)
        return 1;
    if (b & 1)
        return 1ll * a * modpow(a, b - 1) % MOD;
    return modpow(1ll * a * a % MOD, b >> 1);
}

#ifndef _DEBUG
const int MAXN = (1 << 20), SIZE = MAXN * 2 - 1;
#else
const int MAXN = (1 << 2), SIZE = MAXN * 2 - 1;
#endif
//ll dp[MAXN];
//int tmq[MAXN];
//int ctm = 0;
//ll A = 0, B = 0;
//
//int a[MAXN], b[MAXN];
//
//ll get_raw_dp(int x)
//{
//    if (tmq[x] < ctm)
//        return max(0ll, dp[x]);
//    return dp[x];
//}
//
//ll get_dp(int x)
//{
//    return max(0ll, get_raw_dp(x) + A + B * x);
//}
//
//void set_dp(int x, ll y)
//{
//    y -= A;
//    y -= B * x;
//    //dp[x] = max(dp[x], y);
//    dp[x] = y;
//    tmq[x] = ctm;
//}

int a[MAXN], b[MAXN];
ll lst[SIZE], A[SIZE], B[SIZE], C[SIZE];

inline void setval(int v, ll x)
{
    A[v] = 0;
    B[v] = 0;
    C[v] = x;
    lst[v] = x;
}

inline void addval(int v, int sz, ll a, ll b)
{
    A[v] += a;
    B[v] += b;
    lst[v] += a;
    lst[v] += b * (sz - 1ll);
}

inline void push(int v, int l, int r)
{
    if (r - l == 1)
        return;
    if (C[v] != -1)
    {
        {
            setval(2 * v + 1, C[v]);
            setval(2 * v + 2, C[v]);
        }
        C[v] = -1;
    }
    if (A[v] != 0 || B[v] != 0)
    {
        int sz = (r - l) >> 1;
        addval(2 * v + 1, sz, A[v], B[v]);
        addval(2 * v + 2, sz, A[v] + B[v] * sz, B[v]);
        A[v] = B[v] = 0;
    }
}

int ql, qr;
ll qx;
void globset(int v, int l, int r)
{
    if (qr <= l || r <= ql)
        return;
    if (ql <= l && r <= qr)
    {
        setval(v, qx);
        return;
    }
    push(v, l, r);
    globset(2 * v + 1, l, (l + r) >> 1);
    globset(2 * v + 2, (l + r) >> 1, r);
    lst[v] = lst[2 * v + 2];
}

void globget(int v, int l, int r)
{
    if (qr <= l || r <= ql)
        return;
    if (ql <= l && r <= qr)
    {
        qx = lst[v];
        return;
    }
    push(v, l, r);
    int m = (l + r) >> 1;
    globget(2 * v + 1, l, m);
    globget(2 * v + 2, m, r);
}

ll qy;
void globadd(int v, int l, int r)
{
    if (qr <= l || r <= ql)
        return;
    if (ql <= l && r <= qr)
    {
        addval(v, r - l, qx, qy);
        qx += qy * (int)(r - l);
        return;
    }
    push(v, l, r);
    globadd(2 * v + 1, l, (l + r) >> 1);
    globadd(2 * v + 2, (l + r) >> 1, r);
    lst[v] = lst[2 * v + 2];
}

// > qx
int sigurd(int v, int l, int r)
{
    if (qr <= l)
        return qr;
    if (r <= qr)
    {
        if (lst[v] > qx)
            return r;
        if (r - l == 1)
            return l;
    }
    push(v, l, r);
    int m = (l + r) >> 1;
    int sx = sigurd(2 * v + 1, l, m);
    if (sx < m)
        return sx;
    return sigurd(2 * v + 2, m, r);
}

namespace segtree
{
    ll getval(int x)
    {
        ql = x;
        qr = x + 1;
        qx = 0;
        globget(0, 0, MAXN);
        return max(qx, 0ll);
    }

    void setmax(int n, ll mx)
    {
        /*int l = -1, r = n;
        while (r - l > 1)
        {
            int m = (l + r) >> 1;
            if (getval(m) > mx)
                l = m;
            else
                r = m;
        }*/
        qx = mx;
        qr = n;
        int r2 = sigurd(0, 0, MAXN);
        /*if (r != r2)
#ifdef _DEBUG
            _CrtDbgBreak();
#else
            exit(-1);
#endif*/
        ql = r2;
        qr = MAXN;
        globset(0, 0, MAXN);
    }

    void addval(int n, ll x, ll y)
    {
        ql = 0;
        qr = MAXN;
        qx = x;
        qy = y;
        globadd(0, 0, MAXN);
    }
}
/*
2
0 0
1 2
-1 -1
*/

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // memset(tmq, 0, sizeof(tmq));
    memset(A, 0, sizeof(A));
    memset(B, 0, sizeof(B));
    memset(C, -1, sizeof(C));
    memset(lst, 0, sizeof(lst));
    int n;
    //cin >> n;
    scanf("%d", &n);
    for (size_t i = 0; i < n; i++)
    {
        //cin >> a[i] >> b[i];
        scanf("%d %d", a + i, b + i);
        // a[i] = rand();
        // b[i] = rand();
    }/*
    vector <int> p(n);
    for (auto& i : p)
    {
        cin >> i;
        if (i != -1)
            return -1;
    }*/
    for (int i = n - 1; i >= 0; i--)
    {
        segtree::setmax(i + 1, 0);
#ifdef _DEBUG
        cout << "dp = ";
        for (size_t j = 0; j <= i; j++)
        {
            cout << segtree::getval(j) << ' ';
        }
        cout << '\n';
#endif // _DEBUG
        segtree::addval(i + 1, a[i], b[i]);
#ifdef _DEBUG
        cout << "dp = ";
        for (size_t j = 0; j <= i; j++)
        {
            cout << segtree::getval(j) << ' ';
        }
        cout << '\n';
#endif // _DEBUG
        segtree::setmax(i + 1, max(0ll, segtree::getval(i)));
#ifdef _DEBUG
        cout << "dp = ";
        for (size_t j = 0; j <= i; j++)
        {
            cout << segtree::getval(j) << ' ';
        }
        cout << '\n';
#endif // _DEBUG
    }
    cout << segtree::getval(0) << '\n';
//    for (size_t i = 0; i <= n; i++)
//    {
//        dp[i] = -1e18;
//    }
//    for (int i = n - 1; i >= 0; i--)
//    {
//        if (true)
//        {
//            // ll res = 0;
//            ll mx = a[i] + 1ll * i * b[i] + get_dp(i);
//            for (int j = i; j >= 0; j--)
//            {
//                // res = max(res, a[i] + 1ll * j * b[i] + get_dp(j));
//                set_dp(j, max(mx, a[i] + 1ll * j * b[i] + get_dp(j)));
//                
//                // dp[j] = res;
//            }
//        }
//        else
//        {
//            /*for (size_t j = 0; j <= i; j++)
//            {
//                set_dp(j, get_dp(j));
//            }*/
//            ctm++;
//            A += a[i];
//            B += b[i];
//            /*for (size_t j = 0; j <= i; j++)
//            {
//                set_dp(j, get_dp(j) + a[i] + 1ll * j * b[i]);
//            }*/
//        }
//#ifdef _DEBUG
//        cout << "dp = ";
//        for (size_t j = 0; j <= i + 1; j++)
//        {
//            cout << get_dp(j) << ' ';
//        }
//        cout << '\n';
//#endif
//    }
//    cout << get_dp(0) << '\n';
    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
