#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
    // Build a map of words to their frequencies
    unordered_map<string,int> word_to_freq;
    for (string s; cin >> s; ) {
        ++word_to_freq[s];
    }

    // Build a reverse map of frequencies to words
    multimap<int,string> freq_to_words;
    // unordered_multimap<int,string> freq_to_words;
    for (const auto& [word, freq] : word_to_freq) {
        freq_to_words.insert( {freq, word} );
    }

    // Output the reverse map
    for (const auto& [freq, word] : freq_to_words) {
        cout << setw(4) << freq << '|' << word << '\n';
    }

    // Find out how many words occur three times
    auto [b, e] = freq_to_words.equal_range(3);
    if (b != e) {
        auto& freq = b->first;
        auto num_words = distance(b, e);
        cout << '\n' << num_words << " words occur " << freq << " times.\n";
    }
}
