#include<iostream>
#include<map>
using namespace std;
int main()
{
    int n;
    map<int,int>m;
    cin>>n;
    while(n--)
    {
        pair<int,int>i;
        cin>>i.first>>i.second;
        m[i.first]+=i.second;
    }
    for(auto i:m)
        cout<<i.first<<' '<<i.second<<endl;
}