Gratitude
Ben heard about studies by Emmons and McCullough that suggest that intentionally practicing gratitude has a lasting effect on people's happiness. Since he wants to be happy too, he decided that at the end of each day he will think back over the past day and write down three things he is thankful for, one thing per line. At the end of days in which he practiced this exercise, he was curious to know which things appeared most frequently on his list. Help Ben obtain the items for which he was frequently grateful.
Input
The first line contains two integers and . Then follow lines containing Ben’s notes from days. You may assume that the three lines that correspond to the same day contain no repetitions. That is, no chunk contains two identical lines if the input is divided into chunks of consecutive lines.
Each line contains at most (ASCII) characters.
Output
The output should represent the list of things that Ben is grateful for, ordered by frequency of appearance in Ben’s list (with the most frequent item first). When two items have the same frequency, the most recent item should appear first. That is, in case of a tie in the number of appearances, the item whose last appearance is later in the input should appear earlier in the output. Finally, if there are more than different items in Ben’s list, your output should contain only the first items (according to the required order).
Examples
Sample 1. "Good food" is the only item that appears twice in Ben's list, so it should appear first in the output. All other items appear once in the input, but "Being healthy" takes precedence as it is the most recent.
Sample 2. Here there are only different items that Ben is grateful for, so there are only lines of output. In this list, "Good food" is first in the output since it appears twice in the input, and the other items are ordered by last appearance in Ben's list.