Find words used at least once by every user and list them by total frequency, breaking ties alphabetically.
Easy3Hash mapSortingInterviewNo attempts yetTime limit2sMemory limit256 MBThe social networking site My+Din has trouble managing its many popular forums. A recent regulation requires the site to report users who take part in conversations about certain topics. There are far too many users for manual monitoring, so the site asked its interns for a solution.
One intern guessed that a conversation about a given topic uses the same few words over and over. Knowing the most used words would tell investigators which forums to look at.
You are given the conversation log of one forum. Find the words that every single user of that forum used at least once.
The first line contains one integer M (1≤M≤104), the number of messages.
Each of the next M lines holds one message. A line starts with the user's name, which contains no spaces and is at most 20 characters long, and continues with the content of that user's message. The content is a list of words separated by spaces, every word consists of lower case letters, and each message contains at least one word. The total length of all messages, spaces included, is at most 2×106 characters. User names are case sensitive: two names belong to the same user only when the strings are identical. One user may post several messages.
Print the words that every user of the forum used, one per line, ordered from most used to least used. Break ties alphabetically. The use count of a word is the number of times it appears across all messages, counting every repeat inside a message. If there is no such word, print ALL CLEAR.