#C6310. Frequency Analyzer

    ID: 50057 Type: Default 1000ms 256MiB

Frequency Analyzer

Frequency Analyzer

You are given a list of N words. Your task is to analyze the frequency of each word and then output the words along with their frequencies. The output must be sorted primarily by the frequency in descending order and, for words with the same frequency, in lexicographical order in ascending order.

More formally, if a word w appears f times, output a line in the format w f. The sorting criteria can be summarized by the following ordering function:

\( sort(w, f) = (-f, w) \)

For example, if the input is:

5
apple banana apple orange banana

Then the correct output is:

apple 2
banana 2
orange 1

inputFormat

The first line of input contains an integer N, representing the number of words. The second line contains N words separated by spaces.

outputFormat

Output the frequency analysis in multiple lines. Each line should contain a word and its frequency separated by a space. The words must be sorted primarily by frequency in descending order and then by lexicographical order in ascending order if frequencies are equal.

## sample
1
hello
hello 1

</p>