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
program grz;

type
  tab = array[1..1000000] of Qword;
  tab1 = array[1..1000000] of longword;
var
  n: longword;
  a : array[1..1000000] of longword;
  a1 : array[1..1000000] of longword;
  b: array[1..1000000] of Qword;
  b1: array[1..1000000] of Qword;
  m: Qword;

  i,j,k: longword;

  t : text;

procedure qsort(var t:tab; var t1:tab1; l,r:longword);
var
  p,tmp : Qword;
  i,j : longword;
  begin
    i:=l; j:=r;
    tmp:=(l+r) div 2;
    p:=t[tmp]; //element dzielacy;
    repeat
      while t[i]<p do i:=i+1;
      while p<t[j] do j:=j-1;
      if i<=j then
      begin
        tmp:=t[i]; t[i]:=t[j]; t[j]:=tmp;
        tmp:=t1[i]; t1[i]:=t1[j]; t1[j]:=tmp;
        i:=i+1; j:=j-1
      end
    until i>=j;
    if l<j then qsort(t,t1,l,j);
    if i<r then qsort(t,t1,i,r)
  end;

begin
  readln(n);

  for i:=1 to n do
  begin
    read(a[i]);
    readln(b[i]);
  end;
  qsort(b,a,1,n);
  writeln(b[n]);
  for i:=2 to n do
  begin
    for j:=1 to n do
    begin
      a1[j]:=a[j];
      b1[j]:=b[j]+a[j]*(i-1);
    end;
    m:=0;
    for j:=i downto 1 do
    begin
      qsort(b1,a1,1,n);
      m:=m+b1[n];
      if j>1 then
      begin
        for k:=1 to n-1 do
          b1[k]:=b1[k]-a1[k];
        b1[n]:=0; a1[n]:=0;
      end;
    end;
    writeln(m);
  end;
end.