IntermediateLists & Dictionaries25 points

What are customers really saying?

An e-commerce team in Dubai reads thousands of product reviews. Before a human reads anything, a script lists the most used words (ignoring boring ones) and flags the reviews that mention an alert word such as broken or refund.

A word is a run of letters, optionally joined by single apostrophes inside it (don't, it's), taken from the review in lower case. Digits, punctuation and spaces separate words. Stop words are ignored for the frequency list (they are still checked for alert words).

Task: line 1 is K; line 2 lists stop words separated by commas; line 3 lists alert words separated by commas; line 4 is N; then N review lines. First print the K most frequent non-stop words, one per line as word count, ordered by count descending then word ascending (print fewer lines if there are fewer distinct words). Then print Flagged: followed by the 1-based numbers of the reviews that contain at least one alert word, separated by single spaces, or Flagged: none if there are none.

Sample tests

Input

3
the,a,is,it,and,was,i
broken,refund
4
The phone is great, battery is GREAT!
It arrived broken and I want a refund.
Great price, great seller; the screen's fine
Battery 100% fine... battery lasts, don't worry

Expected output

great 4
battery 3
fine 2
Flagged: 2

Input

2
the
scam
2
Lovely lovely day
Nothing to see

Expected output

lovely 2
day 1
Flagged: none

Your answer is also checked against 3 hidden tests.