#include<bits/stdc++.h>

using namespace std;

int main(){

int n;
cin>>n;
int a[n];
unordered_map<int,int> freq;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> minhp;

for(int i=0;i<n;i++){
  cin>>a[i];
  freq[a[i]]++;
}
for(auto i=freq.begin();i!=freq.end();i++){
  minhp.push({i->second,i->first});
  
}
while (minhp.size()>0){
  int j=0;
  int s=minhp.top().first;
  for(j=0;j<s;j++){
    cout<<minhp.top().second<<" ";
  }
  minhp.pop();
}


return 0;
}


Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: