public class Solution { public static void main(String[] args) throws Exception { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); int length = 0; int index =0; ArrayList<String> arrayList = new ArrayList<>(); for (int i = 0; i < 5 ; i++) { arrayList.add(bufferedReader.readLine()); if (arrayList.get(i).length() > length) { length = arrayList.get(i).length(); index = i ; }} for (String x: arrayList) { if (x.length() == arrayList.get(index).length()) System.out.println(x); } } }