import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] types = new int[n]; for(int types_i=0; types_i < n; types_i++){ types[types_i] = in.nextInt(); } // your code goes here int result = getMostCommonBirdType(n, types); System.out.println(result); } public static int getMostCommonBirdType(int birdCount, int[] birdTypes){ if(birdCount == birdTypes.length && 5 <= birdCount && birdCount <= 2*1e5) { Map stats = getStatsByType(birdTypes); ArrayList types = getCommonTypes(stats); return leastCommonType(types); } return 0; } public static Map getStatsByType(int[] birdTypes){ Map types = new HashMap<>(); for (int type: birdTypes) { types.compute(type, (k, v) -> v == null ? 1 : ++v); // v++ doesn't work } return types; } public static ArrayList getCommonTypes(Map typeStats){ int most = 0; ArrayList types = new ArrayList<>(); for (int typeVal: typeStats.values()) { if (typeVal >= most) most = typeVal; } for(Map.Entry entry: typeStats.entrySet()) { if(entry.getValue() == most) types.add(entry.getKey()); } return types; } public static int leastCommonType(ArrayList commonTypes){ int least = 6; for (int type: commonTypes) { if (type <= least) least = type; } return least; } }