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

const int MAXN = 1e6;
const int mod =  998244353;


int bin_pow_mod(int a,int n){
    if(n == 0)return 1;
    if(n % 2 == 0){
        int tmp = bin_pow_mod(a,n / 2);
        return (tmp * tmp) % mod;
    }else{
        return (a * bin_pow_mod(a,n - 1)) % mod;
    }
}
int sz[MAXN];
int p[MAXN];
int h[MAXN];

void dfs(int v,std::vector<std::vector<int>>& g,int pred = -1){
    sz[v] = 1;
    p[v] = pred;
    if(pred == -1){
        h[v] = 0;
    }else{
        h[v] = h[pred] + 1;
    }
    for(int u:g[v]){
        if(u != pred){
            dfs(u,g,v);
            sz[v] += sz[u];
        }
    }
}


int find(int a,int b){
    if(a == -1) return b;
    if(b == -1)return a;

    if(h[a] < h[b]){
        std::swap(a,b);
    }

    while(h[a] > h[b]){
        a = p[a];
    }
    while(a != b){
        a = p[a];
        b = p[b];
    }
    return a;
}



signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);


    int n;
    std::cin>>n;

    std::vector<std::pair<int,int>> all(n);
    for(int i =0 ;i < n;i++){
        std::cin>>all[i].first>>all[i].second;
    }

    std::vector<std::vector<int>> dp(n + 1,std::vector<int>(n + 1,-1e18));
    std::vector<std::vector<int>> pref(n + 1,std::vector<int>(n + 1,-1e18));
    dp[0][0] = 0;
    pref[0][0] = 0;
    for(int j = 1;j <= n;j++){
        pref[0][j] = 0;
    }
    for(int i = 1;i <= n;i++){
        for(int j = 0;j < i;j++){
            for(int prev = j;prev >= 0;prev--){
                dp[i][j] = std::max(dp[i][j],dp[i - 1][prev]);
            }
           // std::cout<<dp[i][j]<<' '<<pref[i - 1][j]<<' '<<i<<' '<<j<<' '<<dp[i - 1][0]<<std::endl;
           dp[i][j] = pref[i - 1][j];
            dp[i][j] += all[i - 1].second * j + all[i - 1].first;
            if(j == 0){
                pref[i][j] = dp[i][j];
            }else{
               // std::cout<<dp[i][j]<<' '<<pref[i][j - 1]<<"sdhf"<<std::endl;
                pref[i][j] = std::max(pref[i][j - 1],dp[i][j]);
            }
        }
        for(int j = 1;j <= n;j++){
            pref[i][j] = std::max(pref[i][j],pref[i][j - 1]);
        }
    }

    int ans = 0;
    for(int i = 0;i <= n;i++){
        for(int j = 0;j <= n;j++){
            // std::cout<<dp[i][j]<<' '<<i<<' '<<j<<std::endl;
            ans = std::max(ans,dp[i][j]);
        }
    }
    std::cout<<ans;
}