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
#include <bits/stdc++.h>
using namespace std;

long long loss[300'002];
int main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> v;
    v.resize(n);
    for(int i = 0; i < n; i++)
        cin >> v[i];
    sort(v.begin(),v.end());
    int last=-1;
    int len=0;
    vector<int> vi;
    for(auto k : v){
        if(k==last)len++;
        else{vi.push_back(len); last = k; len=1;}
    }
    vi.push_back(len);
    //sort(vi.begin(), vi.end());
    //calc loss
    for(auto k : vi){
        if(k==0)continue;
        //cerr << "looking at " << k << '\n';
        int val = k/2;
        loss[2]+=k-val;
        int pos = 2;
        while(val > 0){
            int start=pos+1;
            int end = 300'001;
            while(start < end-1){
                int center = (start+end)/2;
                if(k/center == val){
                    start=center+1;
                }else{
                    end=center;
                }
            }
            //make sure this works.
            if(k/start!=val){
                pos = start;
            }else{
                pos = start+1;
            }
            //cerr << "loss at " << pos << " by " << val-k/pos << '\n';

            //pos = ?;
            loss[pos]+=val-k/pos;
            val = k/pos;
        }
    }


    int val=n;
    for(int i = 1; i <= n; i++){
        val-=loss[i];
        cout << val*i << ' ';
    }
}