eolymp
bolt
Try our new interface for solving problems
Problems

Gift from the Goddess of Programming

Gift from the Goddess of Programming

The goddess of programming is reviewing a thick logbook, which is a yearly record of visitors to her holy altar of programming. The logbook also records her visits at the altar. The altar attracts programmers from all over the world because one visitor is chosen every year and endowed with a gift of miracle programming power by the goddess. The endowed programmer is chosen from those programmers who spent the longest time at the altar \textit{during the goddess's presence}. There have been enthusiastic visitors who spent very long time at the altar but failed to receive the gift because the goddess was absent during their visits. Now, your mission is to write a program that nds how long the programmer to be endowed stayed at the altar during the goddess's presence. \InputFile The input is a sequence of datasets. The number of datasets is less than \textbf{100}. Each dataset is formatted as follows. \textbf{nM_1/D_1 h_1:m_1 e_1 p_1M_2/D_2 h_2:m_2 e_2 p_2...M_n/D_n h_n:m_n e_n p_n} The rst line of a dataset contains a positive even integer, \textbf{n} ≤ \textbf{1000}, which denotes the number of lines of the logbook. This line is followed by \textbf{n} lines of space-separated data, where \textbf{M_i/D_i} identi es the month and the day of the visit, \textbf{h_i : m_i} represents the time of either the entrance to or exit from the altar, \textbf{e_i} is either \textbf{I} for entrance, or \textbf{O} for exit, and \textbf{p_i} identi es the visitor. All the lines in the logbook are formatted in a xed-column format. Both the month and the day in the month are represented by two digits. Therefore April \textbf{1} is represented by \textbf{04/01} and not by \textbf{4/1}. The time is described in the \textbf{24}-hour system, taking two digits for the hour, followed by a colon and two digits for minutes, \textbf{09:13} for instance and not like \textbf{9:13}. A programmer is identi ed by an \textbf{ID}, a unique number using three digits. The same format is used to indicate entrance and exit of the goddess, whose \textbf{ID} is \textbf{000}. All the lines in the logbook are sorted in ascending order with respect to date and time. Because the altar is closed at midnight, the altar is emptied at \textbf{00:00}. You may assume that each time in the input is between \textbf{00:01} and \textbf{23:59}, inclusive. A programmer may leave the altar just after entering it. In this case, the entrance and exit time are the same and the length of such a visit is considered \textbf{0} minute. You may assume for such entrance and exit records, the line that corresponds to the entrance appears earlier in the input than the line that corresponds to the exit. You may assume that at least one programmer appears in the logbook. The end of the input is indicated by a line containing a single zero. \OutputFile For each dataset, output the total sum of the \textit{blessed time} of the endowed programmer. The blessed time of a programmer is the length of his/her stay at the altar during the presence of the goddess. The endowed programmer is the one whose total blessed time is the longest among all the programmers. The output should be represented in minutes. Note that the goddess of programming is not a programmer.
Time limit 1 second
Memory limit 64 MiB
Input example #1
14
04/21 09:00 I 000
04/21 09:00 I 001
04/21 09:15 I 002
04/21 09:30 O 001
04/21 09:45 O 000
04/21 10:00 O 002
04/28 09:00 I 003
04/28 09:15 I 000
04/28 09:30 I 004
04/28 09:45 O 004
04/28 10:00 O 000
04/28 10:15 O 003
04/29 20:00 I 002
04/29 21:30 O 002
20
06/01 09:00 I 001
06/01 09:15 I 002
06/01 09:15 I 003
06/01 09:30 O 002
06/01 10:00 I 000
06/01 10:15 O 001
06/01 10:30 I 002
06/01 10:45 O 002
06/01 11:00 I 001
06/01 11:15 O 000
06/01 11:30 I 002
06/01 11:45 O 001
06/01 12:00 O 002
06/01 12:15 I 000
06/01 12:30 I 002
06/01 12:45 O 000
06/01 13:00 I 000
06/01 13:15 O 000
06/01 13:30 O 002
06/01 13:45 O 003
0
Output example #1
45
120
Source Asia Regional Fukuoka, Japan, 2011-11-13