/*
思路:利用map表自带的排序功能
    1. 先获得输入键值对的个数
    2. 获得 输入的键值对, 保存在 map 表中, 其中键值相同的数据相加
    3. 遍历map表, 打印键值对
*/

#include <cstddef>
#include <iostream>
#include <map>
using namespace std;

int main() {
    size_t cnt;
    cin >> cnt;

    size_t key;
    size_t value;
    map<size_t, size_t> my_map;

    for(size_t i = 0; i < cnt; ++i){
        cin >> key >> value;
        my_map[key] += value;
    }

    for(auto iter : my_map){
        cout << iter.first << " " << iter.second << endl;
    }

    return 0;

}
// 64 位输出请用 printf("%lld")