class Photo: tag = {} def __init__(self,no,M,score,tag): self.no = no self.score = score for t in tag: Photo.tag.setdefault(t,0) Photo.tag[t]+=score @classmethod def show_tag_rank(cls): itms = sorted(cls.tag.items(),key=lambda x:x[0]) itms.sort(key=lambda x:x[1],reverse=True) for cnt,item in enumerate(itms): tag,score = item print(tag,score) if cnt == 9: break N = int(input()) photos = [Photo(int(input()),*map(int,input().split()),input().split()) for i in range(N)] Photo.show_tag_rank()