#include <bits/stdc++.h>
using namespace std;
#define int int64_t

const int INF = (4 * 1e18);

void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 1);
    vector<int> b(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
    }
    vector<int> pa(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        pa[i] = pa[i - 1] + a[i];
    }
    vector<int> pb(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        pb[i] = pb[i - 1] + b[i];
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int u = (i - 1) * b[i] + a[i];
        ans = ans + u;
    }
    int mn = 0;
    int u = 0;
    for (int i = n; i >= 1; i--) {
        int w = (i - 1) * b[i] + a[i];
        u += w;
        mn = min(mn, u);
    }
    cout << ans - u;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}