cswork / OAOpen practice workspace

F5OA #1

Top 3 Trending Hashtags in a Time Window

Estimated EasyJudge-ready

Topics (AI-labelled)StringsHashing

Count how many times each hashtag appears in the tweets within a closed time window, and return the top three, sorted by count in descending order and then by tag in ascending lexicographic order.

This site's standard input/output format and supplementary bounds are as described in this problem.

Input

The first line contains n currentTime timeWindow (n≤2×10^5, total text length ≤10^6, timestamps and the time window are non-negative and ≤10^9). Each of the next n lines contains a timestamp, a tab character, and a tweet; a tag starts with # followed by ASCII letters/digits/underscores.

Output

Output one hashtag per line, keeping the leading #; output nothing if there are no tags.

Example 1

Input:

4 4 2
1	hi #a #b
2	#a !!!
3	no tag
4	#b #b

Output:

#b
#a

Example 2

Input:

2 5 1
3	#z #A
5	#z #a

Output:

#a
#z

Example 3

Input:

3 21 2
17	x #a1 #a
27	x #a1 #a
12	none #_

Output:

Editorial

Loading solution…