#P7632. NBA Lead Duration

    ID: 20825 Type: Default 1000ms 256MiB

NBA Lead Duration

NBA Lead Duration

Slavko has started following the NBA. A game lasts exactly 48 minutes, and after the game the statistics are displayed. Every time a team scores, Slavko writes down the time of the score. He is curious about the total duration each team was in the lead.

The game starts tied at 0-0. Each scoring event adds one point to the team's score. At any moment, if one team has a higher score than the other, that team is considered to be leading; if the scores are equal, no team is in the lead.

You are given the scoring events in chronological order. Each event is provided with a timestamp in mm:ss format and a team number (either 1 or 2). Compute the total time each team was in the lead and output the durations in mm:ss format (with two digits for both minutes and seconds).

Note: The game lasts exactly 48 minutes (i.e. 2880 seconds). When processing the events, accumulate the time intervals during which a team was leading.

inputFormat

The first line contains an integer n (n ≥ 1), the number of scoring events. Each of the following n lines contains a timestamp and an integer separated by a space. The timestamp is in the mm:ss format (representing minutes and seconds) and indicates the time when a team scored. The integer is either 1 or 2, representing the team that scored.

outputFormat

Output two lines. The first line should display the total time Team 1 was in the lead, and the second line should display the total time Team 2 was in the lead. Both durations must be in mm:ss format with two digits for minutes and seconds.

sample

3
01:10 1
16:40 2
45:30 1
18:00

00:00

</p>