#include <iostream>
#include <map>
using namespace std;
int main() {
int n;
cin >> n;
map<int, int> records;
// 读取输入并合并
for(int i = 0; i < n; i++) {
int index, value;
cin >> index >> value;
records[index] += value; // 自动处理重复的index
}
// 按序输出结果
for(const auto& pair : records) {
cout << pair.first << " " << pair.second << endl;
}
return 0;
}
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
// TreeMap自动按键排序
TreeMap<Integer, Integer> records = new TreeMap<>();
// 读取输入并合并
for(int i = 0; i < n; i++) {
int index = sc.nextInt();
int value = sc.nextInt();
records.put(index, records.getOrDefault(index, 0) + value);
}
// 输出结果
for(Map.Entry<Integer, Integer> entry : records.entrySet()) {
System.out.println(entry.getKey() + " " + entry.getValue());
}
}
}
n = int(input())
records = {}
# 读取输入并合并
for _ in range(n):
index, value = map(int, input().split())
records[index] = records.get(index, 0) + value
# 按序输出结果
for index in sorted(records.keys()):
print(index, records[index])