50053. The Most Popular Author

I'm a slow walker, but I never walk backwards.

Task Description

Given a list of books written by each author, and the number of copies each book sold, write a program to find the most popular author who has the most number of copies of books sold.

First we are given the lists of books these authors write. There are $M$ of these author-book pairs, as in the following format. We assume that all strings do not have space and tab space. We also assume that the titles of the books are all different.

1
2
3
4
5
Author_A book_name_a
Author_B book_name_b
.
.
.

Then we are given the number of copies each book was sold($0\leq selling\lt 500$). There are also $M$ lines, and each of them is the number of copies sold and the title of the book.

1
2
3
4
5
book_name_p selling
book_name_q selling
.
.
.

Input Format

The first line is a number $M$ ($0\lt M\lt 100$). Then the following M lines are the lists of author-book pairs, and the next following $M$ lines are the lists of book-selling pairs. The string length of each authors and book names is less than $50$.

Output Format

One line in output is the most popular author and the number of copies of books sold. If some authors have the same selling, output the first lexicographically one.

Sample Input

4
Alice C_programing
Jack Java_programing
Bob Python_programing
Alice C++_programing
Python_programing 5
C++_programing 3
Java_programing 6
C_programing 3

Sample Output

Alice 6

Discussion