/* -*- coding: utf-8 -*- * * 2284.cc: No.2284 Assembly - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ typedef long long ll; /* global variables */ int as[MAX_N], bs[MAX_N]; ll ass[MAX_N + 1], bss[MAX_N + 1]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", as + i, bs + i); for (int i = 0; i < n; i++) ass[i + 1] = ass[i] + as[i], bss[i + 1] = bss[i] + bs[i]; ll sum = 0, fb = 0, ta = 0; for (int i = 0; i < n; i++) { sum += fb * as[i] + ta * bs[i]; if ((ass[n] - ass[i]) * bs[i] >= (bss[n] - bss[i]) * as[i]) fb += bs[i]; else ta += as[i]; } printf("%lld\n", sum); return 0; }