#include <bits/stdc++.h>
using namespace std;

struct man{
	string name;
	int count;
}a[1000];

//排序函数 
bool cmp(man m1,man m2){
//	if(m1.count < m2.count) return m1.count > m2.count?true:false;
//	if(m1.count==m2.count&&m1.name < m2.name) return m1.name > m2.name?true:false; 
	if(m1.count > m2.count){
		return true;
	}else{
		if(m1.count == m2.count && m1.name > m2.name){
			return true;
		}else{
			return false;
		}
	}
} 

int main(){
	int n,i,k = 0,p,j;
	string s;
	
	cin>>n;
	getchar();
	for(i = 0;i < n;i++){
		cin>>s;
		//假设a数组中没有这个名字
		p = -1; 
		for(j = 0;j < k;j++){
			if(a[j].name == s){
				p = j;
				break;
			}
		} 
		
		//如果a数组没有这个人 
		if(p == -1){
			a[k].name = s;
			a[k].count = 1;
			k++;
		}else{
			a[p].count = a[p].count + 1;
		}
	}
	
	//求最高得票人
	sort(a,a+k,cmp);
	
	for(i = 0;i < k;i++){
		cout<<a[i].name<<" "<<a[i].count<<endl;
	}
}


/**************************************************************
	Problem: 1499
	User: admin
	Language: C++
	Result: Accepted
	Time:11 ms
	Memory:2128 kb
****************************************************************/