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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll n_max = 500005;
vector<ll> arr(n_max,-1);
vector<ll>occur;
vector<ll>ans;
void solve(ll n){
    //ans[0] = n;
    for(auto x : occur){
        ll j = 1;
        while(j<=x){
            ans[j-1] = ans[j-1] + x / j * j;
            j++;
        }
    }
    for(auto x : ans) cout << x << " ";
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll n;
    cin >> n;
    arr.resize(n,-1);
    ans.resize(n);

    for(int i = 0;i < n;i++){
        cin >> arr[i];
    }

    sort(arr.begin(),arr.end());        // 1 1 1 2 2 3 3 4 4 4 itd. można łatwo zliczać

    for(int i = 0;i < n;i++){
        if(i != 0 && arr[i] == arr[i-1]) occur[occur.size()-1]++;
        else occur.push_back(1);
    }

    sort(occur.rbegin(),occur.rend());

    solve(n);

    return 0;
}