#1.运用字典的特性去解;
#2.dict[key] = dict.get(key, 0) + value,判断读取的key是否已经存在字典中,如果是新key,则返回0,同时读取初始的value;如果不是新key,则返回原本的value同时累加新的value;
while True:
try:
n = int(input())
dict = {}
for i in range(n):
temp = list(input().split())
key = int(temp[0])
value= int(temp[1])
dict[key] = dict.get(key, 0) + value
for index in sorted(dict):
print(index,dict[index])
except:
break

京公网安备 11010502036488号