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

int main() {
    int n;
    cin >> n;
    map<int, int> count;
    while (n--) {
        int k, v;
        cin >> k >> v;
        count[k] += v;
    }
    for(auto&& [k,v]: count){
        cout << k << " " << v << endl;
    }
    return 0;
    
}
// 64 位输出请用 printf("%lld")

如果用unordered_map输出是无序的,为了保证输出有序,只能用map了