Submissions
시간 제한2초메모리 제한2048 MB
제출 하나만 상태를 바꿀 수 있을 때 금메달을 받을 수 있는 팀을 모두 구한다.
문제
The legend, example, and note of this problem are used fictitiously. Any resemblance to the actual contests, rules, submissions, or teams is coincidental.
In the International Challenging Puzzle Contest (ICPC), there are submissions. You are given the list of submissions ordered by time. A submission can be represented as a tuple , which means team makes a submission on problem at time with status . The status of a submission is either "accepted" or "rejected".
The score of a team is the pair of the number of problems solved by the team and the total time consumed by the team. The larger the number of problems solved is, the higher the score is. If a tie occurs, the smaller the total time consumed is, the higher the score is.
If team makes at least one submission with status "accepted" on problem , we say that team solves problem . A team can get a gold medal if the number of teams with higher score is less than , where is the number of teams that solved at least one problem and denotes the smallest integer that is not smaller than .
You need to find all the teams that can get a gold medal if at most one of the submissions changes its status.
The total time consumed is the sum of times consumed for all solved problems ( if no problems are solved). The time consumed for a solved problem is the time of the first submission with status "accepted", plus times the number of submissions on this problem before the first submission with status "accepted". Note that we say submission is before submission if and only if submission appears earlier than submission in the given list of submissions.
입력
Each test contains multiple test cases. The first line contains a single integer () denoting the number of test cases. For each test case:
The first line contains a single integer () denoting the number of submissions.
The -th of the following lines contains , , , and which mean that team makes a submission on problem at time with status . Specifically:
- is a string of length between and consisting of uppercase letters, lowercase letters, digits and underscores ('
_'). Note that no two teams have the same name. - is an uppercase letter.
- is a non-negative integer less than .
- is a string, being either "
accepted" or "rejected".
It is guaranteed that for all . Recall that if and , we still say that the -th submission came before the -th submission.
It is guaranteed that the sum of over all test cases does not exceed .
출력
For each test case:
Output one integer on the first line, denoting the number of teams that can get a gold medal if at most one of the submissions changes its status.
On the second line, output distinct strings in any order, denoting the names of these teams.
힌트
In the first case of the first example, TS1 solves two problems, so they can get a gold medal. TSxingxing10 can get a gold medal if their first submission changes its status to "accepted".
In the second case of the first example, AllWayTheNorth, XuejunXinyoudui1, LetItRot and ImYourFan have the same score, two problems solved with total time consumed. They can get gold medals simultaneously if no submission changes its status.