1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <vector>
#include <string>
#include <utility>
using namespace std;

#define REP(i, n) for (int i = 1; i <= (n); i++)
#define Y "TAK"

class FinalistsSelector {
    int n;
    vector<pair<int, int>> eligible;
    vector<int> finalists;

public:
    explicit FinalistsSelector(int n) : n(n) {}

    void readData() {
        string s;
        int x;
        REP(i, n) {
            cin >> s >> x;
            if (s == Y) {
                eligible.push_back({i, x});
            }
        }
    }

    void selectFinalists() {
        int count = 0;
        for (size_t i = 0; i < eligible.size() && count < 10; i++) {
            finalists.push_back(eligible[i].first);
            count++;
        }

        for (size_t i = 10; i < eligible.size() && finalists.size() < 20; i++) {
            if (eligible[i].second < 2) {
                finalists.push_back(eligible[i].first);
            }
        }
    }

    void run() const {
        for (int id : finalists) {
            cout << id << " ";
        }
    }
};

int main(){
    int n;
    cin >> n;
    FinalistsSelector selector(n);
    selector.readData();
    selector.selectFinalists();
    selector.run();

    return 0;
}