#include <iostream>
#include<map>
struct CmpByKeyLength {
bool operator()(const int& k1, const int& k2) {
return k1 < k2;
}
};
using namespace std;
int main()
{
int n;
cin>>n;
map<int, int, CmpByKeyLength> mymap;
int a,b;
for(int i=0;i<n;++i){
cin>>a>>b;
if(mymap.find(a) == mymap.end()){
mymap[a] = b;
}else
mymap[a]+=b;
}
for(auto it=mymap.begin();it!=mymap.end();++it){
cout<<it->first<<" "<<it->second<<endl;
}
return 0;
}