// Arup Guha
// 1/16/2023
// Example of using a map in C++
// Does the same thing as election3.java.

using namespace std;

#include <iostream>
#include <map>
#include <string>

int main() {

    int n;
    cin >> n;

    map<string,int> mymap;

    // Process votes.
    for (int i=0; i<n; i++) {
        string name;
        cin >> name;

        map<string,int>::iterator it = mymap.find(name);

        // New item.
        if (it == mymap.end())
            mymap.insert(pair<string,int>(name,1));

        // Add a vote.
        else {
            int value = it->second;
            mymap.erase(name);
            mymap.insert(pair<string,int>(name,value+1));
        }
    }

    // How we can go through the votes in alpha order by key.
    for (map<string,int>::iterator it=mymap.begin(); it != mymap.end(); it++)
        cout << it->first << " " << it->second << endl;

    return 0;
}
