Problem statement is here: http://acm.timus.ru/problem.aspx?space=1&num=1585
Keep a count of each of the types of penguins and you are all set.
public void solve(int testNumber, InputReader in, OutputWriter out) { int[] counter = new int[3]; int n = in.nextInt(); while (n-- > 0) { String penguin = in.readLine(); if (penguin.equalsIgnoreCase("Emperor Penguin")) { counter[0]++; } else if (penguin.equalsIgnoreCase("Macaroni Penguin")) { counter[1]++; } else if (penguin.equalsIgnoreCase("Little Penguin")) { counter[2]++; } } out.println(counter[0] > counter[1] ? (counter[0] > counter[2] ? "Emperor " + "Penguin" : "Little Penguin") : (counter[1] > counter[2] ? "Macaroni Penguin" : "Little " + "Penguin")); }