404342: GYM101484 C Leading the Scoreboard

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Leading the Scoreboardtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Marge is the newest member of GEMA, a programming competition study group at her university. One of the first things she did as a new member was to look at the last year's regionals scoreboard to see how well the team representing her university performed. Looking at it, she noticed that she had no idea how the teams were ranked in the scoreboard. After searching on the internet she found the following text in the rules section of the ACM-ICPC website, describing how teams are ranked in the scoreboard:

"Teams are ranked according to the most problems solved, ... teams who solve the same number of problems are ranked by least total time. The total time is the sum of the time consumed for each problem solved. The time consumed for a solved problem is the time elapsed from the beginning of the contest to the submittal of the accepted run plus 20 penalty minutes for every rejected run for that problem regardless of submittal time. There is no time consumed for a problem that is not solved."

Marge already knows that ACM-ICPC contests have a duration of 300 minutes and, if at any moment there are multiple teams tied for the first position (same number of problems solved and same total time), she considers that all those teams are leading the scoreboard at the same time.

She found the list of submissions of the contest and now she is interested in finding out the total amount of time in minutes that her university's team was leading the scoreboard.

Input

The first line of the input contains three integers N (2 ≤ N ≤ 200), M (1 ≤ M ≤ 104) and P (8 ≤ P ≤ 14), indicating respectively the number of teams in the competition, the total number of submissions and the total number of problems in the contest.

The next N lines contain each a single word, consisting of 1 to 10 uppercase Latin letters, indicating the name of each team. The first team listed corresponds to Marge's university's team.

The next M lines contain each the information about a submission: the name of the team that made the submission, an uppercase letter indicating the problem associated with the submission (one of the first P letters of the alphabet), an integer t (1 ≤ t ≤ 300) indicating the time in minutes at which the submission was made, and a string containing either "OK" (accepted run) or "NO" (rejected run) indicating the result of the submission. The submissions are in nondecreasing order by submitted time (t).

In your calculations, consider that a submission sent at minute t was sent and judged exactly t minutes and 0 seconds after the beginning of the contest.

No team made more than one submission in a given minute and no team submitted an answer for a problem they have already solved.

Output

Output a single integer, the total amount of time in minutes during which Marge's university's team was leading the scoreboard.

ExamplesInput
3 7 8
BOB
BOBAGI
MARGARIDA
BOBAGI A 1 OK
BOB A 16 NO
MARGARIDA A 22 OK
BOB A 30 OK
BOB H 180 OK
BOBAGI C 185 OK
MARGARIDA G 300 OK
Output
6
Input
2 3 10
BOB
CAFE
BOB A 1 OK
CAFE A 2 OK
CAFE J 300 OK
Output
300
Note

In the first example, BOB was leading the scoreboard between minutes 0 and 1 and between minutes 180 and 185.

In the second example, BOB was leading the scoreboard between minutes 0 and 300, but lost the leadership at the last moment.

Source/Category

加入题单

上一题 下一题 算法标签: