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
34
35
36
37
38
39
40
41
42
43
44
45
#include <cstdio>

#define ll long long
#define MIL 1000000

ll* arr(int s) {
  ll* a = new ll[s];
  for(int i=0;i<s;i++) {
    a[i] = 0;
  }
  return a;
}

int main(int argc, char** argv) {
  int n,r,c;
  int* a = new int[256000];
  scanf("%d",&n);
  for(int i=0;i<n;i++) {
    scanf("%d%d",&r,&c);
    a[i] = r;
  }

  ll* u = arr(MIL+2);
  for(int i=0;i<n;i++) {
    u[a[i]]++;
  }
  ll* s = arr(MIL+2);
  ll* zPre = arr(MIL+2);
  ll* zPost = arr(MIL+2);
  for(int i=1;i<=MIL;i++) {
    s[i] = s[i-1] + u[i];
    zPre[i] = zPre[i-1] + ((ll)u[i])*i;
  }
  for(int i=MIL;i>=0;i--) {
    zPost[i] = zPost[i+1] + ((ll)u[i])*i;
  }
  for(int i=0;i<n;i++) {
    int d = a[i];
    ll pre = zPre[MIL] - zPre[d] - (s[MIL] - s[d]);
    ll post = zPost[0] - zPost[d] + s[d-1];
    ll res = pre + post + ((ll)u[a[i]]) * d;
    printf("%lld\n", res);
  }
  return 0;
}