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

const int N = 3e5+5;

unordered_map <int, int> M;
vector <int> ile[N];

int main()
{
    int n;
    cin >> n;
    for (int i=0; i<n; i++)
    {
        int a;
        cin >> a;
        M[a]++;
    }
    
    for (auto it=M.begin(); it!=M.end(); ++it)
    {
        int wart = it->first;
        int l = it->second;
        ile[l].push_back(wart);
    }
    
    int res = 0, licz = 0;
    for (int i=n; i>=1; i--)
    {
        licz += ile[i].size();
        res = licz * i;
        cout << res;
    }

    return 0;
}