package com.javarush.task.task18.task1803; /* Самые частые байты */ import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Map; public class Solution { public static void main(String[] args) throws Exception { BufferedReader reader = null; String fileName; BufferedReader fileReader = null; HashMap<Integer, Integer> map = new HashMap<>(); try { reader = new BufferedReader(new InputStreamReader(System.in)); fileName = reader.readLine(); fileReader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName))); int nextInt = 0; while (fileReader.read() != -1) { if (fileReader.read() != -1) { nextInt = fileReader.read(); if (map.keySet().contains(nextInt)) { map.put(nextInt, map.get(nextInt) + 1); } else map.put(nextInt, 1); } } } catch (IOException e) { e.printStackTrace(); } finally { try { reader.close(); fileReader.close(); ArrayList<Integer> count = new ArrayList<>(map.values()); int maxCount = Collections.max(count); for (Map.Entry entry : map.entrySet()) { if (entry.getValue().equals(maxCount)) { System.out.print(entry.getKey() + " "); } } } catch (IOException e) { e.printStackTrace(); } } } }