"…… A problem is solved when it is accepted by the judges. 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."
- ACM/ICPC Contest Rules
You are writing a new ranking system for ACM/ICPC Contests. During a contest, you may receive the following kinds of request from participants:
●
Submission(Format: S [minute]:[Team No]:[Problem ID]:[Result])
If a team submits a problem which they have already solved, or the last valid submission of the same team is less than 5 minutes ago, then this submission should be considered invalid and ignored by your system; otherwise, the submission is valid and saved for further processing - if the result is 1 (Correct), then this submission should be considered accepted by the system.
●
Query a team's rank on the rank list.(Format: R [Team No])
Sort the teams according to the contest rules mentioned above. A tie may occur between two teams who solved equal number of problems and same penalty.
A rank list example can see below.
Two teams who solved same amount of problems and have same penalty always have same rank.
●
Query the team with rank K on the rank list.(Format: T [k])
If a tie occurs, i.e. there are more than one team with rank K, return the team which the first get last accepted submission (according to the input order) (If they are all zero solved problem , just return the team with small number). If there is not a team with rank K, return -1 instead.
Initially every team has no submissions, and the contest will last no more than 5 hours.