https://www.acmicpc.net/problem/1159
package boj.String;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class boj_1159 {
public static void main(String[] args) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
int count = Integer.parseInt(r.readLine());
StringBuilder result = new StringBuilder();
List<String> arr = new ArrayList<>();
while(count-->0){
arr.add(r.readLine());
}
Map<String, Long> collect = arr.stream().map(i -> i.substring(0, 1))
.collect(Collectors.groupingBy(i -> i, Collectors.counting()));
collect.entrySet().stream()
.filter(entry -> entry.getValue() >= 5)
.map(Map.Entry::getKey)
.sorted()
.forEach(result::append);
if (result.length() == 0) {
result.append("PREDAJA");
}
System.out.println(result);
}
}