import java.util.*;
public class Main{
static class Element{
int value,freq;
Element(int value,int freq){
this.value = value;
this.freq = freq;
}
}
public static void main(String[] args) {
sort(new int[]{2,2,4,5,7,6,4,8,3,9,5,7,2});
}
public static void sort(int a[]){
Map<Integer,Integer> map = new HashMap<>();
for(int i=0;i<a.length;++i){
map.merge(a[i], 1, Integer::sum);
}
PriorityQueue<Element> pq = new PriorityQueue<Element>(1000,(c,d) -> (d.freq - c.freq));
for(Map.Entry<Integer,Integer> m : map.entrySet()){
pq.offer(new Element(m.getKey(),m.getValue()));
}
while(!pq.isEmpty()){
Element e = pq.poll();
System.out.println(e.value + " => " + e.freq);
}
}
}