QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 10

#10235. Finalists [C]

統計

This year you have finally decided to make it to the Potyczki finals! Before you do, it is worth learning exactly what the qualification rules for the final are. In the competition regulations, you found the following points:

  • After five remote rounds, 20 participants will be qualified for the competition final. Ten of them are the contestants ranked from 1 to 10 on the A+B+C ranking list. The next ten are the highest-ranked contestants from the subsequent positions, excluding those who have participated in the Potyczki Algorytmiczne final at least twice.
  • Only contestants who are citizens of Poland, or are residents of Poland, or are learning, studying, or working in Poland can be qualified for the final.
  • In order to select the 20 participants qualified for the final, first, the participants who cannot qualify for it or who resign from participating are removed from the ranking. Then, from the remaining participants, 20 finalists are selected according to the rules described above.

Your colleague knows all the contestants very well and has predicted what this year's ranking will look like. They gave you a list of $n$ contestants numbered from 1 to $n$ in order of their scores (there are no ties on your colleague's list). For each contestant, you know whether they can and want to participate in the final and how many times they have participated in the final before.

Determine the list of 20 contestants who will be qualified for the final according to the regulations.

You can assume that there are enough contestants on the list to fill all 20 spots according to the regulations.

Input

The first line contains an integer $n$ ($20 \le n \le 10\,000$), representing the number of contestants in the Potyczki ranking.

The next $n$ lines contain information about the subsequent contestants. Each of them contains a word $s$ and an integer $x$ ($s \in \{\text{TAK}, \text{NIE}\}$, $0 \le x < 20$). The word TAK means that the contestant can and wants to participate in the final, the word NIE means that the contestant cannot or does not want to participate in the final. The number $x$ represents the contestant's current number of starts in the final.

Output

Output one line containing 20 integers separated by single spaces, representing the numbers of the contestants qualified for the Potyczki final in ascending order.

Examples

Input 1

35
NIE 0
NIE 0
TAK 3
TAK 0
TAK 7
TAK 5
NIE 0
NIE 0
TAK 7
TAK 1
NIE 0
TAK 8
TAK 1
TAK 3
NIE 0
TAK 2
NIE 0
TAK 1
NIE 4
TAK 2
TAK 2
TAK 1
TAK 1
TAK 0
TAK 0
TAK 0
TAK 0
TAK 0
NIE 0
TAK 1
TAK 2
TAK 0
TAK 0
TAK 0
TAK 0

Output 1

3 4 5 6 9 10 12 13 14 16 18 22 23 24 25 26 27 28 30 32

Note

Explanation of the example: Contestants numbered 1, 2, 7, 8, 11, 15, 17, 19, 29 are skipped because they cannot/do not want to participate in the final. The ten best contestants among the remaining ones have numbers 3, 4, 5, 6, 9, 10, 12, 13, 14, 16. Then, skipping contestants numbered 20, 21, and 31, because they have already been in the final at least twice, we get the second ten finalists with numbers: 18, 22, 23*, 24, 25, 26, 27, 28, 30, 32.

*Your colleague predicts that contestant number 23 will win the final!

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.