#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <vector>
#include <climits>
#include <string>
#include <algorithm>
#include <sstream>
using namespace std;

vector<string> split(string haystack, string needle) {
    vector<string> result;
    int startPos = 0;
    int foundPos = haystack.find(needle, startPos);
    while (foundPos != string::npos) {
        int count = foundPos - startPos;
        string token = haystack.substr(startPos, count);
        if (!token.empty()) {
            result.push_back(token);
        }
        startPos = foundPos + needle.length();
        foundPos = haystack.find(needle, startPos);
    }
    string token = haystack.substr(startPos, haystack.length() - startPos);
    if (!token.empty()) {
        result.push_back(token);
    }
    return result;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;getline(cin, s);
    
    vector<string> parts = split(s, " ");

    map<string, int> mp;
    for (int i = 0;i < parts.size();i++) {
        mp[parts[i]]++;
    }

    for (auto entry : mp) {
        cout << entry.first << " " << entry.second << endl;
    }

    for (auto value : parts) {
        if (mp[value] != 0) {
            cout << value << " " << mp[value] << endl;
            mp[value] = 0;
        }
    }
    return 0;
}

