#K46467. Reading List Genre Analysis

    ID: 27983 Type: Default 1000ms 256MiB

Reading List Genre Analysis

Reading List Genre Analysis

Alice has a reading list of books, each tagged by a genre. Your task is to analyze the list and determine two things:

  • The number of unique genres present in the list.
  • The genre or genres that appear most frequently. If there is a tie, output the tied genres in alphabetical order separated by a single space.

Note: The genres provided are case-sensitive. The input is read from standard input and the output should be printed to standard output.

In mathematical notation, if we define the set \(G\) of genres and a counting function \(f(g)\) for \(g \in G\), then you need to compute \(|G|\) and the set \(\{g \in G: f(g)=\max_{h \in G} f(h)\}\). The resulting set should be sorted in lexicographical order and printed as a space separated string.

inputFormat

The input is given via standard input and is structured as follows:

  1. The first line contains an integer \(n\) representing the number of books.
  2. The following \(n\) lines each contain a single string representing the genre of a book.

outputFormat

Print the analysis result on standard output in two lines:

  • The first line contains the number of unique genres.
  • The second line contains the most frequent genre(s) as a space separated string in lexicographical order.
## sample
7
mystery
fantasy
mystery
sci-fi
fantasy
fantasy
mystery
3

fantasy mystery

</p>