fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. Scanner sc=new Scanner(System.in);
  14. int n=sc.nextInt();
  15. int a[]=new int[n];
  16. for(int i=0;i<n;i++)
  17. a[i]=sc.nextInt();
  18.  
  19. TreeMap<Integer,Integer> m=new TreeMap<>(Collections.reverseOrder());
  20. for(int ele:a)
  21. m.put(ele,m.getOrDefault(ele,0)+1);
  22. int ans=0;
  23. List<Map.Entry<Integer,Integer>> li=new ArrayList<>(m.entrySet());
  24.  
  25. for(int i=0;i<li.size()-1;i++)
  26. {
  27. // ans+=hash.getValue();
  28. li.get(i+1).setValue( li.get(i+1).getValue()+li.get(i).getValue());
  29. ans+=li.get(i).getValue();
  30. li.get(i).setValue(0);
  31.  
  32. }
  33.  
  34. System.out.println(ans);
  35.  
  36. }
  37. }
Success #stdin #stdout 0.15s 54544KB
stdin
5
4 5 5 2 4
stdout
6