Contest scoreboard
Time: 1 s · Memory: 256 MB
- Sorting
Statement
teams numbered from to take part in a contest. Problems are numbered from to . Each submission is written as four values: team, problem, time (in minutes) and verdict — C (correct) or I (incorrect).
A problem is solved by a team at its first C; later submissions to that problem are ignored. The penalty for a solved problem is the time of the first C plus minutes for every I before it. I submissions to an unsolved problem give no penalty.
Build the scoreboard of the teams that made at least one submission: by the number of solved problems in decreasing order, ties by total penalty in increasing order, then by team number in increasing order.
Input format
The first line contains and (, ). The next lines contain submissions in non-decreasing order of time: team number, problem number (–), time (–) and the letter C or I.
Output format
For every team a separate line: team number, number of solved problems and total penalty.
Examples
Input
4 6 1 2 10 I 3 1 11 C 1 2 19 C 1 2 21 C 1 1 25 C 2 5 40 I
Output
1 2 64 3 1 11 2 0 0
Note
For every team and problem keep two values: whether it is solved and how many I there were. After reading all submissions sort the teams by three keys.
In the example team 1 solved problem 2 at minute 19 after one I: , and problem 1 at minute 25: in total. The C at minute 21 is ignored. Team 2 solved nothing but submitted, so there is a line 2 0 0; team 4 made no submissions and is not listed.
Source: UVa 10258.
