#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
struct Cow{
long long v, x;
int id;
}cow[20002];
int n; // cnt 记录删点的个数
long long sum_x[20002], cnt[20002], ans;
bool cmp1(Cow a, Cow b){ return a.x < b.x; }
bool cmp(Cow a, Cow b) { return a.v > b.v; }
void add(int x, long long val, long long *p)
{
while (x <= n) {
p[x] += val;
x += x&(-x);
}
}
long long get_sum(int x, long long *p)
{
long long re = 0;
while (x) {
re += p[x];
x -= x&(-x);
}
return re;
}
int main()
{
scanf("%d", &n);
for (int i=1; i<=n; i++) scanf("%lld %lld", &cow[i].v, &cow[i].x);
sort(cow+1, cow+n+1, cmp1);
for (int i=1; i<=n; i++) add(i, cow[i].x, sum_x);
for (int i=1; i<=n; i++) cow[i].id = i;
sort(cow+1, cow+1+n, cmp);
int now_x, id, now_v;
for (int i=1; i<=n; i++) {
now_x = cow[i].x;
now_v = cow[i].v;
id = cow[i].id;
ans = ans + ( now_x*(id-1 + get_sum(id-1, cnt)) - get_sum(id-1, sum_x)
+ get_sum(n, sum_x) - get_sum(id, sum_x) - now_x*( n-id + (get_sum(n, cnt) - get_sum(id, cnt)) ) )
* now_v;
add(id, -1ll, cnt);
add(id, -1ll*now_x, sum_x);
}
cout<<ans<<endl;
}
注意:cnt 是 -1 的修改, cnt 求和前是加号