cswork / OA打开练习工作台

AmazonOA #310

Most Common Product Pair

估计简单可在线判题

考点(AI 标注)哈希计数字符串

Product names may repeat within a transaction, but a pair of distinct products counts only once per transaction. Pairs are unordered: first sort the two names lexicographically. Find the product pair that appears together in the most transactions; on a tie, take the lexicographically smallest name pair. If there is no pair of distinct products at all, output −1 as this site's protocol specifies.

输入格式

The first line contains the number of transactions T, followed by one line per transaction: k and then k product names. The original bounds are 1≤T≤1000 and 1≤k≤100 per transaction, and names consist of uppercase letters. This site adds 1≤length≤100. The total number of distinct products overall is not limited, and 100000 distinct products are allowed.

输出格式

Output the two names in lexicographic order, smallest first, separated by a space; if there is no pair of distinct products, output −1.

样例 1

输入:

3
3 A B B
2 B C
2 A B

输出:

A B

样例 2

输入:

1
3 C B A

输出:

A B

样例 3

输入:

2
2 A A
1 B

输出:

-1

样例说明

The answers are A B, A B and −1. In the second example all three pairs have frequency 1, so they are compared lexicographically as ordered tuples of the two names.