1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <cstdio>
#include <algorithm>
using namespace std;
typedef pair<long long, long long> pll;
const int MX=1000100;
int n,i,j,k,c;
long long r;
pll a[MX];
bool u[MX];
bool cmp(const pll& x, const pll& y) {
  return x>y;
}
int main() {
  scanf("%d",&n);
  for (i=0; i<n; i++) {
    scanf("%lld%lld",&a[i].first,&a[i].second);
    a[i].second-=a[i].first;
  }
  sort(a,a+n,cmp);
  for (i=0; i<n; i++) {
    for (k=-1, j=0; j<n; j++) {
      a[j].second+=a[j].first;
      if (!u[j] && (k==-1 || a[j].second>a[k].second)) k=j;
    }
    u[k]=true;
    for (r=j=c=0; c<=i; j++) if (u[j]) {
      r+=a[j].second-c*a[j].first;
      c++;
    }
    printf("%lld\n",r);
  }
  return 0;
}