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
76
77
78
79
#include <iostream>
using namespace std;
int n;
long long a[2000000],b[2000000];
long long licz[4000000];
long long sum[4000000];
bool flag[2000000];
int r=1;
long long result=0;
void insert(int a, long long c)
{
    a=a+r+1;
    while(a>=1)
    {
        sum[a]+=c;
        licz[a]++;
        a=a>>1;
    }
}
long long query_licz(int a,int b)
{
    a=a+r+1;
    b=b+r+1;
    long long res=0;
    while(a/2!=b/2)
    {
        if(a%2==0)res+=licz[a+1];
        if(b%2==1)res+=licz[b-1];
        a=a>>1;
        b=b>>1;
    }
    return res;
}
long long query_sum(int a,int b)
{
    a=a+r+1;
    b=b+r+1;
    long long res=0;
    while(a/2!=b/2)
    {
        if(a%2==0)res+=sum[a+1];
        if(b%2==1)res+=sum[b-1];
        a=a>>1;
        b=b>>1;
    }
    return res;
}
void take()
{
    long long maks=0,nr=0;
    for(int i=0;i<n;i++)
    {
        if(flag[i]==0)
        {
            long long tmp=result+b[i]+a[i]*query_licz(-1,a[i])+query_sum(a[i]-1,1000005);
            if(tmp>maks)
            {
                maks=tmp;
                nr=i;
            }
        }
    }
    flag[nr]=1;
    result=maks;
    //cout<<nr<<" - "<<a[nr]<<" "<<b[nr]<<"   ";
    insert(a[nr],a[nr]);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i]>>b[i];
    while(r<1000000)r=r<<1;
    for(int i=0;i<n;i++)
    {
        take();
        cout<<result<<endl;
    }
}