a = int(input()) b = {} for i in range(a): key = input().split(" ") k = int(key[0]) v = int(key[1]) try: b[k] += v except KeyError: b[k] = v # 按键升序排序并输出 for k in sorted(b): print(k, b[k], end="\n")