import java.util.*; import java.io.*; public class Main{ public static void main(String[] args) throws IOException, ClassNotFoundException{ boolean[] f = new boolean[100005]; for(int i=2; i a = (ArrayList) ois.readObject(); TreeMap hm = new TreeMap<>(); a.forEach(e ->{ if(f[e]){ if(hm.get(e) == null) hm.put(e, 1); else hm.put(e, hm.get(e)+1); } }); hm.forEach((k, v) -> { System.out.println(k + " " + v); }); } }