#C8071. Sorted Hashtags by Popularity
Sorted Hashtags by Popularity
Sorted Hashtags by Popularity
You are given a list of social media posts. Your task is to extract all hashtags from these posts and output them sorted by their popularity. The popularity of a hashtag is determined by the following criteria:
- The number of posts in which the hashtag appears (a hashtag appearing multiple times in one post counts as one).
- If two hashtags appear in the same number of posts, the one with a higher total occurrence across all posts comes first.
- If they are still tied, the hashtags are sorted in lexicographical order (i.e. the usual alphabetical order).
Mathematically, for a hashtag \(h\), let \(p(h)\) be the number of posts in which it appears, and \(t(h)\) be its total number of occurrences. We sort hashtags by the tuple \[ (-p(h), -t(h), h) \] in that order.
inputFormat
The first line contains an integer \(n\) representing the number of posts.
Each of the following \(n\) lines contains a string representing a social media post. A post may contain zero or more hashtags; a hashtag is defined as a word starting with the character '#' and having at least one character following it.
outputFormat
Output the sorted hashtags, one per line, following the order defined in the problem description.
## sample1
#test
#test
</p>