#K60047. Finding the Most Similar Users

    ID: 30999 Type: Default 1000ms 256MiB

Finding the Most Similar Users

Finding the Most Similar Users

You are given a list of users along with their interests. Each user is identified by a unique string and has one or more interests. Your task is to find the pair of users with the highest number of common interests.

Formally, if user i has interests set (S_i) and user j has interests set (S_j), the similarity between the two users is defined as:

[ \text{similarity}(i,j) = |S_i \cap S_j| ]

If there are multiple pairs of users with the same maximum number of common interests, output the first pair encountered in the order of input (i.e. the pair with the smallest indices in the input order).

All input is read from standard input (stdin) and all output should be written to standard output (stdout).

inputFormat

The first line contains an integer (n) (with (n \ge 2)) that denotes the number of users. Each of the next (n) lines describes a user in the following format:

username m interest1 interest2 ... interest_m

Here, username is a string without spaces, (m) is an integer representing the number of interests for that user, followed by (m) strings each representing an interest. All tokens are separated by spaces.

outputFormat

Output a single line containing two usernames separated by a space. These represent the pair of users with the maximum number of common interests.## sample

4
Alice 2 reading cycling
Bob 2 reading gaming
Charlie 2 cycling baking
Dana 2 reading cooking
Alice Bob

</p>