def solution(genres, plays):
answer = []
tmpGenreDict = {}
songDict = {}
for i in range(len(genres)):
genre = genres[i]
playTime = plays[i]
if genre not in songDict:
songDict[genre] = {}
tmpGenreDict[genre] = 0
songDict[genre][i] = playTime
tmpGenreDict[genre] += playTime
tmpGenreDict = sorted(tmpGenreDict.items(), key=lambda x: x[1], reverse=True)
for arr in tmpGenreDict:
sortedSongs = sorted(songDict[arr[0]].items(), key=lambda x: x[1], reverse=True)
curCnt = 0
for idx in sortedSongs:
if curCnt >= 2:
continue
answer.append(idx[0])
curCnt += 1
return answer