cswork / OAOpen practice workspace

AmazonOA #310

Most Common Product Pair

Estimated EasyJudge-ready

Topics (AI-labelled)HashingStrings

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.

Input

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

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

Example 1

Input:

3
3 A B B
2 B C
2 A B

Output:

A B

Example 2

Input:

1
3 C B A

Output:

A B

Example 3

Input:

2
2 A A
1 B

Output:

-1

Example notes

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.

Editorial

Loading solution…