Chefs from all over the globe gather each year for an international convention. Each chef represents some country. Please, note that more than one chef can represent a country.
Each of them presents their best dish to the audience. The audience then sends emails to a secret and secure mail server, with the subject being the name of the chef whom they wish to elect as the "Chef of the Year".
You will be given the list of the subjects of all the emails. Find the country whose chefs got the most number of votes, and also the chef who got elected as the "Chef of the Year" (the chef who got the most number of votes).
Note 1
If several countries got the maximal number of votes, consider the country with the lexicographically smaller name among them to be a winner. Similarly if several chefs got the maximal number of votes, consider the chef with the lexicographically smaller name among them to be a winner.
Note 2
The string A = a1a2...an is called lexicographically smaller then the string B = b1b2...bm in the following two cases:
- there exists index i ≤ min{n, m} such that aj = bj for 1 ≤ j < i and ai < bi;
- A is a proper prefix of B, that is, n < m and aj = bj for 1 ≤ j ≤ n.
The characters in strings are compared by their ASCII codes.
Refer to function strcmp in C or to standard comparator < for string data structure in C++ for details.

-----Input-----
The first line of the input contains two space-separated integers N and M denoting the number of chefs and the number of emails respectively. Each of the following N lines contains two space-separated strings, denoting the name of the chef and his country respectively. Each of the following M lines contains one string denoting the subject of the email.

-----Output-----
Output should consist of two lines. The first line should contain the name of the country whose chefs got the most number of votes. The second line should contain the name of the chef who is elected as the "Chef of the Year".

-----Constraints-----
- 1 ≤ N ≤ 10000 (104)
- 1 ≤ M ≤ 100000 (105)
- Each string in the input contains only letters of English alphabets (uppercase or lowercase)
- Each string in the input has length not exceeding 10
- All chef names will be distinct
- Subject of each email will coincide with the name of one of the chefs

-----Example 1-----
Input:
1 3
Leibniz Germany
Leibniz
Leibniz
Leibniz

Output:
Germany
Leibniz

-----Example 2-----
Input:
4 5
Ramanujan India
Torricelli Italy
Gauss Germany
Lagrange Italy
Ramanujan
Torricelli
Torricelli
Ramanujan
Lagrange

Output:
Italy
Ramanujan

-----Example 3-----
Input:
2 2
Newton England
Euclid Greece
Newton
Euclid

Output:
England
Euclid

-----Explanation-----
Example 1. Here we have only one chef Leibniz and he is from Germany. Clearly, all votes are for him. So Germany is the country-winner and Leibniz is the "Chef of the Year".
Example 2. Here we have chefs Torricelli and Lagrange from Italy, chef Ramanujan from India and chef Gauss from Germany. Torricelli got 2 votes, while Lagrange got one vote. Hence the Italy got 3 votes in all. Ramanujan got also 2 votes. And so India got 2 votes in all. Finally Gauss got no votes leaving Germany without votes. So the country-winner is Italy without any ties. But we have two chefs with 2 votes: Torricelli and Ramanujan. But since the string "Ramanujan" is lexicographically smaller than "Torricelli", then Ramanujan is the "Chef of the Year".
Example 3. Here we have two countries with 1 vote: England and Greece. Since the string "England" is lexicographically smaller than "Greece", then England is the country-winner. Next, we have two chefs with 1 vote: Newton and Euclid. Since the string "Euclid" is lexicographically smaller than "Newton", then Euclid is the "Chef of the Year".

Difficulty: interview

Starter code:

Solutions:

N,M = [int(i) for i in input().split()]

get_country = {}
for i in range(N):
    name,country = input().split()
    get_country[name] = country

country_votes = {}
name_votes = {}
for i in range(M):
    name = input()
    country_votes[get_country[name]] = country_votes.get(get_country[name],0) + 1
    name_votes[name] = name_votes.get(name,0) + 1

win_country = None
votes = -float('inf')
for i,j in country_votes.items():
    if(j>votes):
        win_country = i
        votes = j
    elif(j==votes and i<win_country):
        win_country = i

win_name = None
votes = -float('inf')
for i,j in name_votes.items():
    if(j>votes):
        win_name = i
        votes = j
    elif(j==votes and i<win_name):
        win_name = i

print(win_country)
print(win_name)


count_per={}
per={}
count={}
s=list(map(int,input().split()))
for i in range(s[0]):
    x=input().split()
    count_per[x[0]]=x[1]
for j in range(s[1]):
    y=input()
    try:
        per[y]+=1
    except:
        per[y]=1
    try:
        count[count_per[y]]+=1
    except:
        count[count_per[y]]=1
a=-1
for i,j in count.items():
    if(a<j):
        a=j
        p=i
    elif(a==j):
        if(p>i):
            p=i
print(p)
a=-1
for i,j in per.items():
    if(a<j):
        a=j
        p=i
    elif(a==j):
        if(p>i):
            p=i
print(p)

# cook your dish here
from  collections import defaultdict

chef_country=defaultdict(str)
country=defaultdict(int)
name=defaultdict(int)

a, b = list(map(int, input().split()))
c, n = 0, 0
country_name, chef_name = [], []

for i in range(a):
    p, q = list(map(str, input().split()))
    chef_country[p]=q 

for i in range(b):
    q=input()
    country[chef_country[q]]+=1 
    name[q]+=1 
    if country[chef_country[q]]>c:
        c=country[chef_country[q]]
        country_name=[chef_country[q]]
        
    elif country[chef_country[q]]==c:
        country_name.append(chef_country[q])
        
    if name[q]>n:
        n=name[q]
        chef_name=[q]
        
    elif name[q]==n:
        chef_name.append(q)

country_name.sort()        
chef_name.sort()

print(country_name[0])
print(chef_name[0])

# cook your dish here
count_per={}
per={}
count={}
s=list(map(int,input().split()))
for i in range(s[0]):
    x=input().split()
    count_per[x[0]]=x[1]
for j in range(s[1]):
    y=input()
    try:
        per[y]+=1
    except:
        per[y]=1
    try:
        count[count_per[y]]+=1
    except:
        count[count_per[y]]=1
a=-1
for i,j in count.items():
    if(a<j):
        a=j
        p=i
    elif(a==j):
        if(p>i):
            p=i
print(p)
a=-1
for i,j in per.items():
    if(a<j):
        a=j
        p=i
    elif(a==j):
        if(p>i):
            p=i
print(p)

count_per={}
per={}
count={}
s=list(map(int,input().split()))
for i in range(s[0]):
    x=input().split()
    count_per[x[0]]=x[1]
for j in range(s[1]):
    y=input()
    try:
        per[y]+=1
    except:
        per[y]=1
    try:
        count[count_per[y]]+=1
    except:
        count[count_per[y]]=1
a=-1
for i,j in count.items():
    if(a<j):
        a=j
        p=i
    elif(a==j):
        if(p>i):
            p=i
print(p)
a=-1
for i,j in per.items():
    if(a<j):
        a=j
        p=i
    elif(a==j):
        if(p>i):
            p=i
print(p)

# cook your dish here
n,m=map(int,input().split())
l,d,k={},{},{}
for i in range(n):
    a,b=input().split()
    k[a]=b
    l[a]=0
    d[b]=0
for u in range(m):
    s=input()
    l[s]+=1
    d[k[s]]+=1
x=0
r=''
for i in d:
    if(d[i]==x):
        if(i<r):
            r=i
    elif(d[i]>x):
        x=d[i]
        r=i
x=0
rr=''
for i in l:
    if(l[i]==x):
        if(i<rr):
            rr=i
    elif(l[i]>x):
        x=l[i]
        rr=i
print(r)
print(rr)


n,m=map(int,input().split())
d={}
for j in range(n):
    c,con=input().split()
    d[c]=con
v={}
for j in range(m):
    c=input()
    if c in v:
        v[c]+=1 
    else:
        v[c]=1
cv={}
w=0
for j in v:
    if d[j] in cv:
        cv[d[j]] +=v[j]
    else:
        cv[d[j]]=v[j]
    if cv[d[j]] >w:
        w=cv[d[j]]
        wc=d[j]
    elif cv[d[j]]==w:
        if d[j]<wc:
            wc=d[j]
print(wc)
wv=0
for j in v:
    if v[j]>wv:
        wv=v[j]
        wc=j 
    elif v[j]==wv:
        if j<wc:
            wc=j 
print(wc)

w,x=map(int,input().split())
s={}
s1={}
s2={}
for i in  range(w):
    a,b=input().split()
    s[a]=b
for i in range(x):
    a=input()
    s1[a]=s1.get(a,0)+1
    s2[s[a]]=s2.get(s[a],0)+1
m1=max(s2.values())
c=[]
for a,b in s2.items():
    if(b==m1):
        c.append(a)
print(min(c))
r=max(s1.values())
d=[]
for a,b in s1.items():
    if(b==r):
        d.append(a)
print(min(d))

x,y=map(int,input().split())
s={}
s1={}
s2={}
for i in  range(x):
    a,b=input().split()
    s[a]=b
for i in range(y):
    a=input()
    s1[a]=s1.get(a,0)+1
    s2[s[a]]=s2.get(s[a],0)+1
m1=max(s2.values())
c=[]
for a,b in s2.items():
    if(b==m1):
        c.append(a)
print(min(c))
r=max(s1.values())
d=[]
for a,b in s1.items():
    if(b==r):
        d.append(a)
print(min(d))