#C3079. Most Sold Genre
Most Sold Genre
Most Sold Genre
You are given the number of books sold, N, and a list of N book genres. Your task is to determine the genre with the highest sales count and the number of times it was sold. In case multiple genres have the same sales count, you must choose the genre that appears first in the input order.
The solution should read input from stdin and output the result to stdout in a single line, with the genre and its count separated by a space.
Mathematically, let \( g_1,g_2,\ldots, g_N \) be the list of genres and define a frequency function \( f(g) \) giving the number of occurrences of genre \( g \). Then the answer is the genre \( g^* \) satisfying:
[ g^* = \min{ g \mid f(g) = \max_{h} f(h) \text{ and } g \text{ appears first among those with maximum count}}, ]
and the output should be: \( g^* \) and \( f(g^*) \).
inputFormat
The first line contains an integer \( N \) denoting the number of books sold. The second line contains \( N \) strings separated by spaces, where each string denotes the genre of a sold book.
outputFormat
Output a single line containing the genre with the highest sale count and the corresponding count, separated by a space.
## sample6
fantasy mystery romance fantasy mystery fantasy
fantasy 3