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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <list>
#include <algorithm>
using namespace std;
struct Polana {
  bool operator<(const Polana& polana) const{
    return this->a<polana.a;
  }
  long long a;
  long long b;
  long long c;
  bool deleted;
};
Polana polany[1000001];
int main(int argc, char **argv){
  int n;
  scanf("%d", &n);
  
  for(int i = 0 ; i < n ; i++){
    scanf("%lld %lld", &polany[i].a,&polany[i].b);
    polany[i].deleted = false;
  }
  sort(polany, polany+n);
  int k = n-1;
  long long zebrano=0;
  long long prev_sum = 0;
  for(int i=n-1; i>=0; i--){
    zebrano+=polany[i].a*i + polany[i].b;
    polany[i].c=polany[i].a*i + polany[i].b + prev_sum;
    prev_sum+=polany[i].a;
  }
  long long res[n];
  res[n-1] = zebrano;
  for(int i=n-2; i>=0; i--){
//    cout<<"kkk\n";
//          for(int j = 0; j<n;j++) {
//        if(!polany[j].deleted) {
//          cout<<polany[j].a <<" " <<polany[j].b <<" "<<polany[j].c<<"\n";
//        }
//      }
    int min_polana = -1;
    for(int j = 0; j<n;j++) {
      if(!polany[j].deleted && (min_polana== -1 || polany[min_polana].c>polany[j].c)){
        min_polana = j;
      }
    } 
    res[i] = res[i+1] - polany[min_polana].c;
    bool is_after = false;
    for(int j = 0; j<n;j++) {
      if(polany[j].deleted) {
        continue;
      }
      if(j == min_polana){
        is_after = true;
        continue;
      }
      if(is_after){
        polany[j].c -= polany[j].a;
      } else {
        polany[j].c -= polany[min_polana].a;
      }
      
    }
    
    polany[min_polana].deleted=true;
    
  }
  for(int i=0; i<n;i++) {
    printf("%lld\n", res[i]);
  }
  return 0;
}