def solution(genres, plays):
gg1 = {i:0 for i in genres}
gg2 = {i:[] for i in genres}
for i,genre in enumerate(genres):
gg1[genre] += plays[i]
a = [i,plays[i]]
gg2[genre].append(a)
for i,genre in enumerate(genres):
gg2[genre].sort(key = lambda x:(-x[1],x[0]))
k = sorted(gg1.items(), key = lambda x:-x[1])
gg1 = dict(k) ; answer = []
for i in gg1.keys():
if len(gg2[i])>=2:
for j in gg2[i][:2]:
answer.append(j[0])
else:
answer.append(gg2[i][0][0])
return answer