#include<bits/stdc++.h> #define x first #define y second #define PI pair<int, int> #define ll long long usingnamespacestd; ll n, sum, res; pair<int, int> p[200005]; intmain(){ cin >> n; for (int i = 1; i <= n; i++) cin >> p[i].x >> p[i].y; sort(p + 1, p + n + 1, [](PI a, PI b) { return a.x * b.y < b.x * a.y; }); for (int i = 1; i <= n; i++) { res += sum * p[i].y; sum += p[i].x * 2; } cout << res << '\n'; return0; }