This page is still under construction.

Parts of this page are still being built. What you see may change.

Gift from the Goddess of Programming

Time limit1sMemory limit128 MB

Summary
Each log line records the entrance or exit of a visitor or the goddess (ID 000). Find the visitor who spends the most time at the altar while the goddess is present.
Level

Medium5 of 10

Topics
Simulation, Sorting, Implementation, Intervals
Solved
No attempts yet

Problem

The goddess of programming is reviewing a thick logbook, a yearly record of the visitors to her holy altar of programming. The logbook also records the goddess's own visits to the altar.

The altar attracts programmers from all over the world, because every year one visitor is chosen and endowed with the gift of miraculous programming power by the goddess. The chosen programmer is picked among those who spent the longest time at the altar while the goddess was present. There have been enthusiastic visitors who spent a very long time at the altar but failed to receive the gift, because the goddess was absent during their visits.

Your task is to write a program that finds how long the programmer who will be endowed stayed at the altar while the goddess was present.

Input

The input is a sequence of datasets. The number of datasets is less than 100. Each dataset is formatted as follows.

n
M1/D1 h1:m1 e1 p1
M2/D2 h2:m2 e2 p2
.
.
.
Mn/Dn hn:mn en pn

The first line of a dataset contains a positive even integer n≤1000n \le 1000, the number of lines in the logbook. It is followed by nn lines of space-separated data, where Mi/DiM_i/D_i gives the month and day of the visit, hi:mih_i:m_i is the time of an entrance to or an exit from the altar, eie_i is either I for an entrance or O for an exit, and pip_i identifies the visitor.

Every line of the logbook uses a fixed-column format. Both the month and the day are written with two digits, so April 1 is written as 04/01, not 4/1. The time uses the 24-hour clock, with two digits for the hour, a colon, and two digits for the minute, for example 09:13 rather than 9:13. A programmer is identified by a unique three-digit ID. The goddess's entrances and exits use the same format, and her ID is 000.

All lines of the logbook are sorted in ascending order of date and time. Because the altar closes at midnight, it is emptied at 00:00. You may assume that every time in the input is between 00:01 and 23:59, inclusive.

A programmer may leave the altar immediately after entering it. In that case the entrance and exit times are equal and the length of the visit is considered 0 minutes. For such records you may assume that the entrance line appears before the corresponding exit line in the input. 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.

Output

For each dataset, output the total blessed time of the endowed programmer. The blessed time of a programmer is the length of their stay at the altar while the goddess is present. The endowed programmer is the one whose total blessed time is the longest among all programmers. The output is expressed in minutes. Note that the goddess of programming is not a programmer.

Examples5

  1. Example 1

    Input
    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
    
    Expected output
    45
    120
    
  2. Example 2

    Input
    2
    04/21 09:00 I 001
    04/21 09:30 O 001
    0
    
    Expected output
    0
    
  3. Example 3

    Input
    4
    05/01 10:00 I 000
    05/01 10:00 I 001
    05/01 11:00 O 001
    05/01 11:00 O 000
    0
    
    Expected output
    60
    
  4. Example 4

    Input
    4
    04/29 20:00 I 002
    04/29 20:30 I 000
    04/29 21:00 O 000
    04/29 21:30 O 002
    4
    05/01 08:00 I 000
    05/01 08:00 I 003
    05/01 08:20 O 003
    05/01 09:00 O 000
    0
    
    Expected output
    30
    20
    
  5. Example 5

    Input
    4
    05/01 09:00 I 005
    05/01 09:30 I 000
    05/01 09:45 O 000
    05/01 10:00 O 005
    0
    
    Expected output
    15