#include <cstdio>
#include <algorithm>
#include <vector>
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define int64 long long
using namespace std;
const int N = 250 * 1000 + 7;
const int B = 300;
int a[N], b[N], bucket[N], n;
vector< pair<int, int> > alla, allb;
struct t_bucket {
int pos;
vector<int> elems;
vector< pair<int, int64> > data, lines;
vector<int64> pts;
void add_elem(int elem) {
vector<int>::iterator pos = lower_bound(elems.begin(), elems.end(), elem);
elems.insert(pos, elem);
}
int64 ceiling(int64 a, int64 b) {
return (a + b - 1) / b;
}
void add(int value) {
add_elem(value);
lines.clear();
data.clear();
pts.clear();
for (int i = 0; i < sz(elems); ++i) {
if ((i == 0) || (elems[i] != elems[i - 1])) {
lines.pb(mp(elems[i], elems[i] * (int64) (sz(elems) - i)));
}
}
pts.pb(0);
data.pb(lines[0]);
for (int i = 1; i < sz(lines); ++i) {
while (!data.empty() && (lines[i].fs * (int64) pts.back() + lines[i].sc >= data.back().fs * (int64) pts.back() + data.back().sc)) {
data.pop_back();
pts.pop_back();
}
pts.pb(data.empty() ? 0 : max(0LL, ceiling(data.back().sc - lines[i].sc, lines[i].fs - data.back().fs)));
data.pb(lines[i]);
}
pos = 0;
}
int64 get_value(int pos, int size) {
return data[pos].fs * (int64) size + data[pos].sc;
}
int64 get_best(int size) {
if (data.empty()) {
return 0;
}
while ((pos + 1 < sz(data)) && (get_value(pos + 1, size) >= get_value(pos, size))) {
pos++;
}
return get_value(pos, size);
}
} buckets[N / B + 1];
int64 get_answer() {
int size = 0;
int64 best = 0;
for (int i = 0; i <= (n - 1) / B; ++i) {
best = max(best, buckets[i].get_best(size));
size += sz(buckets[i].elems);
}
return best;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d%d", &b[i], &a[i]);
alla.pb(mp(a[i], i));
allb.pb(mp(b[i], i));
}
sort(alla.rbegin(), alla.rend());
for (int i = 0; i < n; ++i) {
bucket[alla[i].sc] = i / B;
}
sort(allb.begin(), allb.end());
int64 best = 0;
for (int i = 0; i < n; ++i) {
int num = allb[i].sc;
best = max(best, get_answer() + (n - i) * (int64) b[num]);
buckets[bucket[num]].add(a[num]);
}
printf("%lld\n", best);
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBtcCBtYWtlX3BhaXIKI2RlZmluZSBmcyBmaXJzdAojZGVmaW5lIHNjIHNlY29uZAojZGVmaW5lIHN6KGEpICgoaW50KSAoYSkuc2l6ZSgpKQojZGVmaW5lIGludDY0IGxvbmcgbG9uZwp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE4gPSAyNTAgKiAxMDAwICsgNzsKY29uc3QgaW50IEIgPSAzMDA7CgppbnQgYVtOXSwgYltOXSwgYnVja2V0W05dLCBuOwp2ZWN0b3I8IHBhaXI8aW50LCBpbnQ+ID4gYWxsYSwgYWxsYjsKCnN0cnVjdCB0X2J1Y2tldCB7CglpbnQgcG9zOwoJdmVjdG9yPGludD4gZWxlbXM7Cgl2ZWN0b3I8IHBhaXI8aW50LCBpbnQ2ND4gPiBkYXRhLCBsaW5lczsKCXZlY3RvcjxpbnQ2ND4gcHRzOwoKCXZvaWQgYWRkX2VsZW0oaW50IGVsZW0pIHsKCQl2ZWN0b3I8aW50Pjo6aXRlcmF0b3IgcG9zID0gbG93ZXJfYm91bmQoZWxlbXMuYmVnaW4oKSwgZWxlbXMuZW5kKCksIGVsZW0pOwoJCWVsZW1zLmluc2VydChwb3MsIGVsZW0pOwoJfQoKCWludDY0IGNlaWxpbmcoaW50NjQgYSwgaW50NjQgYikgewoJCXJldHVybiAoYSArIGIgLSAxKSAvIGI7Cgl9CgoJdm9pZCBhZGQoaW50IHZhbHVlKSB7CgkJYWRkX2VsZW0odmFsdWUpOwoJCWxpbmVzLmNsZWFyKCk7CgkJZGF0YS5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