#include <string>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

vector<int> solution(vector<string> genres, vector<int> plays) {
    vector<int> answer;
    
    unordered_map<string, int> album;
    unordered_map<string, unordered_map<int, int>> albumlist;
    
    for (int i = 0; i < genres.size(); ++i) {
        album[genres[i]] += plays[i];
        albumlist[genres[i]][i] = plays[i];
    }
    
    while (album.size() > 0) {
        string genre;
        int max = 0;
    
        for (const auto& al : album) {
            if (max < al.second) {
                max = al.second;
                genre = al.first;
            }
        }
    
        for (int i = 0; i < 2; ++i) {
            int temp = 0;
            int num = -1;
        
            for (const auto& ali : albumlist[genre]) {
                if (temp < ali.second) {
                    temp = ali.second;
                    num = ali.first;
                }
            }
            
            if (num == -1)
                break;
        
            answer.emplace_back(num);
            albumlist[genre].erase(num);
        }
        
        album.erase(genre);
    }
    
    return answer;
}