import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.HashMap;
public class Main {
private static boolean isLetter(char c) {
return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
}
private static void increaseFrequency(Map<StringBuilder, Integer> words, StringBuilder currentWord) {
if (words.containsKey(currentWord)) {
words.put(currentWord, words.get(currentWord) + 1);
} else {
words.put(currentWord, 1);
}
}
private static boolean isMoreFrequent
(String currentWord,
String recurrentWord,
int currentOcurance,
int maxOcurance
) { return (currentOcurance > maxOcurance) || (currentOcurance == maxOcurance && (recurrentWord == null || recurrentWord.compareTo(currentWord) > 0));
}
Map<StringBuilder, Integer> words = new HashMap<>();
int maxOcurance = 0;
while (reader.ready()) {
String currentLine
= reader.
readLine(); StringBuilder currentWord = new StringBuilder();
boolean wasLetter = false;
int length = currentLine.length();
for (int i = 0; i < length; ++i) {
if (isLetter(currentLine.charAt(i))) {
currentWord.append(currentLine.charAt(i));
wasLetter = true;
} else if (wasLetter) {
increaseFrequency(words, currentWord);
if (isMoreFrequent(currentWord.toString(), recurrentWord, words.get(currentWord), maxOcurance)) {
recurrentWord = currentWord.toString();
maxOcurance = words.get(currentWord);
}
currentWord = new StringBuilder();
wasLetter = false;
}
}
if (currentWord.length() > 0) {
increaseFrequency(words, currentWord);
if (isMoreFrequent(currentWord.toString(), recurrentWord, words.get(currentWord), maxOcurance)) {
recurrentWord = currentWord.toString();
maxOcurance = words.get(currentWord);
}
}
}
return recurrentWord;
}
System.
out.
println(frequestWord
(reader
)); }
}
aW1wb3J0IGphdmEuaW8uQnVmZmVyZWRSZWFkZXI7CmltcG9ydCBqYXZhLmlvLklPRXhjZXB0aW9uOwppbXBvcnQgamF2YS5pby5JbnB1dFN0cmVhbVJlYWRlcjsKaW1wb3J0IGphdmEudXRpbC5NYXA7CmltcG9ydCBqYXZhLnV0aWwuSGFzaE1hcDsKCnB1YmxpYyBjbGFzcyBNYWluIHsKICAgIHByaXZhdGUgc3RhdGljIGJvb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VjdXJyZW50V29yZCA9IG51bGw7CiAgICAgICAgaW50IG1heE9jdXJhbmNlID0gMDsKICAgICAgICB3aGlsZSAocmVhZGVyLnJlYWR5KCkpIHsKICAgICAgICAgICAgU3RyaW5nIGN1cnJlbnRMaW5lID0gcmVhZGVyLnJlYWRMaW5lKCk7CiAgICAgICAgICAgIFN0cmluZ0J1aWxkZXIgY3VycmVudFdvcmQgPSBuZXcgU3RyaW5nQnVpbGRlcigpOwogICAgICAgICAgICBib29sZWFuIHdhc0xldHRlciA9IGZhbHNlOwogICAgICAgICAgICBpbnQgbGVuZ3RoID0gY3VycmVudExpbmUubGVuZ3RoKCk7CiAgICAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbGVuZ3RoOyArK2kpIHsKICAgICAgICAgICAgICAgIGlmIChpc0xldHRlcihjdXJyZW50TGluZS5jaGFyQXQoaSkpKSB7CiAgICAgICAgICAgICAgICAgICAgY3VycmVudFdvcmQuYXBwZW5kKGN1cnJlbnRMaW5lLmNoYXJBdChpKSk7CiAgICAgICAgICAgICAgICAgICAgd2FzTGV0dGVyID0gdHJ1ZTsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAod2FzTGV0dGVyKSB7CiAgICAgICAgICAgICAgICAgICAgaW5jcmVhc2VGcmVxdWVuY3kod29yZHMsIGN1cnJlbnRXb3JkKTsKICAgICAgICAgICAgICAgICAgICBpZiAoaXNNb3JlRnJlcXVlbnQoY3VycmVudFdvcmQudG9TdHJpbmcoKSwgcmVjdXJyZW50V29yZCwgd29yZHMuZ2V0KGN1cnJlbnRXb3JkKSwgbWF4T2N1cmFuY2UpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHJlY3VycmVudFdvcmQgPSBjdXJyZW50V29yZC50b1N0cmluZygpOwogICAgICAgICAgICAgICAgICAgICAgICBtYXhPY3VyYW5jZSA9IHdvcmRzLmdldChjdXJyZW50V29yZCk7CgogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBjdXJyZW50V29yZCA9IG5ldyBTdHJpbmdCdWlsZGVyKCk7CiAgICAgICAgICAgICAgICAgICAgd2FzTGV0dGVyID0gZmFsc2U7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGN1cnJlbnRXb3JkLmxlbmd0aCgpID4gMCkgewogICAgICAgICAgICAgICAgaW5jcmVhc2VGcmVxdWVuY3kod29yZHMsIGN1cnJlbnRXb3JkKTsKICAgICAgICAgICAgICAgIGlmIChpc01vcmVGcmVxdWVudChjdXJyZW50V29yZC50b1N0cmluZygpLCByZWN1cnJlbnRXb3JkLCB3b3Jkcy5nZXQoY3VycmVudFdvcmQpLCBtYXhPY3VyYW5jZSkpIHsKICAgICAgICAgICAgICAgICAgICByZWN1cnJlbnRXb3JkID0gY3VycmVudFdvcmQudG9TdHJpbmcoKTsKICAgICAgICAgICAgICAgICAgICBtYXhPY3VyYW5jZSA9IHdvcmRzLmdldChjdXJyZW50V29yZCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlY3VycmVudFdvcmQ7CiAgICB9CgogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgdGhyb3dzIElPRXhjZXB0aW9uIHsKICAgICAgICBCdWZmZXJlZFJlYWRlciByZWFkZXIgPSBuZXcgQnVmZmVyZWRSZWFkZXIobmV3IElucHV0U3RyZWFtUmVhZGVyKFN5c3RlbS5pbikpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihmcmVxdWVzdFdvcmQocmVhZGVyKSk7CiAgICB9Cn0=