Remove known nicknames and collapse whitespace in each message, then report whether the resulting text has appeared before.
Medium4StringHash mapImplementationSimulationNo attempts yetTime limit2sMemory limit512 MBMirko recently discovered IRC (Internet Relay Chat) and quickly became a moderator of several popular channels. Spammers are a big problem for him: they flood a channel with the same message over and over, and the other users cannot hold a real conversation. Mirko heard about an automatic moderation method called "R9K mode" and asked you to help him implement it. In R9K mode, repeated messages are blocked automatically, with one extra condition: every nickname that appears in a message is ignored.
The method works exactly as follows.
Mirko, Slavko, 0cool, and AcidBurn.., hyphen -, comma ,, semicolon ;, question mark ?, and exclamation mark !).Mirko i Slavko ce biti na CERC-u. and Puno srece na natjecanju zele vam organizatori!.Mirko and Slavko, the message Mirko i Slavko ce biti na CERC-u. becomes _i__ce_biti_na_CERC-u. (an underscore stands for a space), and the message !Mirko.Slavko? becomes !.?. Nothing is deleted from the message MirkoSlavko._i__ce_biti_na_CERC-u. becomes _i_ce_biti_na_CERC-u. (an underscore stands for a space)._i_ce_biti_na_CERC-u. becomes i_ce_biti_na_CERC-u. (an underscore stands for a space).BRISI if the transformed message has appeared before, and OSTAVI if it has not.The first line contains two positive integers N and M: the number of nicknames and the number of messages.
The second line contains the N nicknames, separated by spaces.
Each of the next M lines contains one message, in the order the messages arrived in the channel.
The whole input has fewer than 2 million characters in total, and the nicknames and messages follow the rules given in the statement.
Print M lines, one for each message. On each line, print BRISI if the message must be deleted or OSTAVI if it is kept.