参考:
1、https://www.cnblogs.com/bymo/p/8335502.html
2、https://blog.csdn.net/qq_36575363/article/details/108930409
n=int(input())
dic={}
for index in range(n):
ls=input()
if 'append'in ls:
temp=[int(i) for i in ls.split()[1:]]
x,y=temp[0],temp[1]
if x in dic:
dic[x]=dic[x]+y
else:
dic[x]=y
if ls=='query':
if len(dic)<=10 and len(dic)>0:
s = sorted(dic.items(), key=lambda x:(-x[1], x[0]))
print([x[0] for x in s])
elif len(dic)>10:
s = sorted(dic.items(), key=lambda x:(-x[1], x[0]))[:10]
print([x[0] for x in s])
else:
print('null')