#K12851. Most Frequent Marble Color by Size

    ID: 23782 Type: Default 1000ms 256MiB

Most Frequent Marble Color by Size

Most Frequent Marble Color by Size

You are given a list of marbles, where each marble is described by two attributes: its size and its color. The task is to determine, for each distinct size, the color that appears most frequently. In case of a tie (i.e. multiple colors appear with the same frequency), choose the color that comes first in alphabetical order.

The output should list the result for each size, sorted in increasing alphabetical order of the sizes. Each result is presented as a combination of the size and the chosen color, separated by a space.

Note: The input will be provided via standard input (stdin) and the output should be printed to standard output (stdout).

inputFormat

The first line contains an integer n representing the number of marbles. Each of the following n lines contains two strings separated by a space: the first string is the size and the second string is the color of a marble.

Example:

7
small red
large blue
medium green
small blue
medium green
large red
small red

outputFormat

For each unique marble size (sorted alphabetically), output a line with the size and the most frequent color for that size (separated by a single space). In case of a tie in frequency, the color that is lexicographically smaller should be chosen.

Example:

large blue
medium green
small red
## sample
1
small red
small red