#include<bits/stdc++.h>
using namespace std;
struct tp{
	string mz;
	int c;
}a[2000];
bool cmp(tp x,tp y){
	if(x.c>y.c||(x.c==y.c&&x.mz>y.mz)) return true;
	else return false;
}
int main(){
	int n,k=0;
	string x;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x;
		bool f=false;
		for(int j=1;j<=k;j++){
			if(a[j].mz==x){
				a[j].c++;
				f=true;
				break;
			}
		}
		if(f==false){
			k++;
			a[k].mz=x;
			a[k].c=1;
		}
	}
	
	sort(a+1,a+1+k,cmp);
	for(int i=1;i<=k;i++){
		cout<<a[i].mz<<" "<<a[i].c<<endl;
	} 


	
	
	
	
} 
/**************************************************************
	Problem: 1499
	User: zhuanghaoxiang
	Language: C++
	Result: Accepted
	Time:8 ms
	Memory:2168 kb
****************************************************************/