import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] types = new int[n]; Map birds = new HashMap(); for(int types_i=0; types_i < n; types_i++){ types[types_i] = in.nextInt(); if(birds.containsKey(types_i)) { birds.put(type_i, (birds.get(type_i) + 1)); }else{ birds.put(type_i, 1); } } Map sortedMap = birds.entrySet().stream() .sorted(Entry.comparingByValue()) .collect(Collectors.toMap(Entry::getKey, Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); for (Entry entry : sortedMap.entrySet()) { System.out.println("Type " + entry.getKey() + ": "+ entry.getValue() + " bird" + (entry.getValue()==1)?"":"s"); } } }