import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Scanner; import java.util.Set; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } HashMap map=new HashMap(); int duplicateValue= 0; int count=1; for (int name : a) { if(map.containsKey(name)==false){ map.put(name,count); } else if(map.containsKey(name)==true){ int i=map.get(name); i=i+1; map.put(name,i); } } Set entrySet = map.entrySet(); // Obtaining an iterator for the entry set Iterator it = entrySet.iterator(); Entry maxEntry = null; while(it.hasNext()){ Map.Entry me = (Map.Entry)it.next(); } int maxValueInMap=(Collections.max(map.values())); for (Entry entry : map.entrySet()) { // Itrate through hashmap if (entry.getValue()==maxValueInMap) { System.out.println(entry.getValue()); // Print the key with max value } } } }