72 - ZOJ Monthly, November 2008 - I
Long long ago, there was a little boy called Ihsataw. Ihsataw was so fond of computer programming that in almost every contest he got a high rank. Whenever he got a first prize, he promised to BG all the others in the near future in Louwailou, a famous restaurant located near West Lake in Hangzhou. Here the word "BG" means to invite someone to eat food for free.
Year by year Ihsataw has made several promises, yet none of these have been realized. Suspicion grows and all people start wondering whether Ihsataw has gone back on his words.
With this question someone starts to collect the words Ihsataw has said, and then arranges them into several dialogues. All these dialogues are about Ihsataw's BG. Each dialogue is a set of sentences said by Ihsataw or others. Some sentences said by Ihsataw contain information about the date and time, and we consider legal ones of them are the time Ihsataw wants to BG others. Please note that only legal ones are valid.
However, as you may know, Ihsataw's English is not as good as his programming ability. Therefore he may make some spelling mistakes in his words. In one time-sequence (See definition below) he may misspell one letter(a-zA-Z) at most. What's more, Ihsataw never says long sentence, so there will be no more than one legal time-sequence in a sentence.
With current date and time given, your task is to find whether you can make sure that Ihsataw has gone back on his words(i.e. Ihsataw promised to BG sometime but when that day arrived Ihsataw still did not BG. In other words, the earliest BG time is strictly less than current time. )
The input contains multiple test cases, separated with a blank line.
The first line of each case contains an integer N ( 0 <= N <= 20 ) and a time T, representing the number of dialogues and the current time, and then N dialogues follow. Each dialogue starts with an integer C ( 0 <= C <= 20 ), which is the number of sentences. Then C lines follow. Each line is a sentence, consisting three parts: the talker's name (only letters), a colon ':', then the content of the sentence. In the content of sentences words are separated by one or more spaces or punctuation marks. Every sentence is ended with a punctuation mark, but a sentence may be surrounded by one or more spaces. Spaces are only used to separate different words, so you can safely ignore extra spaces. The input is case-insensitive.
Every legal time-sequence the input is formatted like "aaa bbb dd HH:MM:SS YYYY", consisting five parts separated with one or more spaces. The whole legal time-sequence is considered as a word.
Please process to the end-of-file.
For each test case output "Yes" if you can make sure that Ihsataw has gone back on his words, otherwise output "No". One test case per line.
1 Mon Jul 14 19:03:57 2008 3 Ihsataw: I will bg all at Tue Jul 15 19:03:57 2008! Kimi: Really? Ihsataw: Of course. 2 Wed Jul 16 19:03:57 2008 3 Ihsataw: I will bg all at Thu Jul 17 19:03:57 2008! Kimi: Really? Ihsataw: Of course. 3 Ihsataw: I think we should change the date to Tue Dry 15 19:03:57 2008, oh sorry, it is Tue Jul 15 19:03:57 2008. Kimi: Why? Ihsataw: Because I think 15 is a charming number: it is 1/2 of 30, the number of days in a month.
Author: LI, Cheng