public static void main(String[] args) throws Exception { ArrayList<String> strings = new ArrayList<>(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); ArrayList<Integer> stringSize = new ArrayList<>(); for(int i=0;i<10;i++){ String s = bufferedReader.readLine(); strings.add(s); stringSize.add(s.length()); } Collections.sort(stringSize); String max = ""; int maxIndex = 0; String min = ""; int minIndex = 0; for(String s:strings){ if(s.length()==stringSize.get(0)){ min = s; minIndex = strings.indexOf(s); } if(s.length()==stringSize.get(9)){ max = s; maxIndex = strings.indexOf(s); } } if(maxIndex>minIndex){ System.out.println(min); }else { System.out.println(max); } }