#K68472. Library Inventory Management

    ID: 32872 Type: Default 1000ms 256MiB

Library Inventory Management

Library Inventory Management

You are given several datasets representing libraries' inventories. For each dataset, the first line contains an integer n which indicates the number of book titles that follow. The next n lines each contain a book title. A dataset with n = 0 indicates the end of input and should not be processed.

Your task is to determine for each dataset:

  • The number of distinct book titles.
  • The book title that appears most frequently. If there is a tie, choose the lexicographically smallest title.

Print the results for each dataset on a separate line in the format:

[ \text{<number_of_distinct_titles>}\ \text{<most_frequent_title>} ]

Note that the input and output are provided via standard input and standard output.

inputFormat

The input consists of multiple datasets. Each dataset begins with an integer n (where n ≥ 0) on its own line, which represents the number of book titles in that dataset. This is followed by n lines, each containing a book title. The input terminates when a dataset starts with 0.

outputFormat

For each dataset (except the terminating dataset with 0), output a single line containing two elements separated by a space: first, the number of distinct book titles, and second, the most frequently occurring title. If more than one title has the maximum frequency, output the lexicographically smallest one.

## sample
4
Harry Potter and the Sorcerer's Stone
The Hobbit
Harry Potter and the Chamber of Secrets
The Hobbit
6
To Kill a Mockingbird
1984
The Great Gatsby
1984
The Catcher in the Rye
To Kill a Mockingbird
7
A Tale of Two Cities
War and Peace
War and Peace
Moby Dick
The Odyssey
War and Peace
Moby Dick
0
3 The Hobbit

4 1984 4 War and Peace

</p>