#C211. Top Trending Hashtags

    ID: 45390 Type: Default 1000ms 256MiB

Top Trending Hashtags

Given a collection of social media posts and an integer \( n \), extract all hashtags (words starting with '#' followed by alphanumeric characters or underscores). The extraction should be case-insensitive (i.e., treat '#Python' and '#python' as the same hashtag). Return the \( n \) most frequently occurring hashtags in descending order of their frequency. In case of a tie, the hashtag that appears first in the input order should come first.

If there are fewer than \( n \) distinct hashtags, output all available hashtags. If no hashtags are found, output an empty line.

inputFormat

The input is provided via standard input (stdin) in the following format:

  1. An integer \( m \) representing the number of posts.
  2. Followed by \( m \) lines, each containing a post (string).
  3. An integer \( n \) on a new line, denoting the number of top trending hashtags to output.

outputFormat

Output the top \( n \) hashtags separated by a single space on one line. If no hashtags are found, output an empty line.

## sample
5
Loving the #sunshine and the #beach #sunshine
Learning #Python and loving it #python
The #beach is so relaxing #relax
Time to code some more #python #coding
Feeling grateful for the #sunshine and #goodvibes
3
#sunshine #python #beach