Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i.
Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen.
Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces atcoder, he will not earn money even if there are blue cards with atcoderr, atcode, btcoder, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)
At most how much can he earn on balance?
Note that the same string may be written on multiple cards.
Constraints
N and M are integers.
1 \leq N, M \leq 100
s_1, s_2, ..., s_N, t_1, t_2, ..., t_M are all strings of lengths between 1 and 10 (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
M
t_1
t_2
:
t_M
Output
If Takahashi can earn at most X yen on balance, print X.
Examples
Input
3
apple
orange
apple
1
grape
Output
2
Input
3
apple
orange
apple
5
apple
apple
apple
apple
apple
We need to find maximum possible net earnings (blue count minus red count) by choosing a string to announce. Blue cards earn +1 if string matches exactly, red cards lose 1 if string matches exactly. So net for a chosen string S is: (#blue cards with string S) - (#red cards with string S). However, note that we are allowed to choose any string (not necessarily appearing on any card). If we choose a string that does not appear on any blue or red card, net = 0. But we could also get negative net, but we want maximum. So we should compute for each string that appears on either blue or red, the net value (blueCount - redCount). Then also consider strings not appearing: net = 0. So answer = max(0, max over all strings (blueCount - redCount) ).
But caution: if the best net is negative, we could choose a string not appearing, so answer 0. So answer = max(0, max net).
But in example 2: Blue: apple, orange, apple => blueCount for apple = 2, orange=1. Red: five apples => redCount for apple=5. net for apple = 2-5=-3; orange=1-0=1; others=0. max net is 1, answer 1. So that matches.
Example 3: Blue: voldemort (1), Red: voldemort x10 (10). net for voldemort = 1-10=-9; max net among others? any other string? Not given, but answer is 0 because we can choose a different string not on any card, net 0. So answer 0.
Edge cases: Strings may be duplicate across both colors.
Thus algorithm: read N, s_i strings, count map blueCount; read M, t_i strings, count map redCount. Then iterate over all keys in union of keys, compute diff = blueCount[key] - redCount[key]; keep max. Also consider 0. Print max.
N,M up to 100, strings length <=10. So trivial.
Let's double-check: Are there any constraints about choosing a string that does not appear on any card? The problem says: "Takahashi will now announce a string, and then check every card." So any string is allowed. If it doesn't match any card, he earns 0 and loses 0, net 0. So yes.
Thus answer is max(0, max_{S} (count_blue[S] - count_red[S]) ).
Implementation: Python.
Pseudo:
def solve():
import sys
input = sys.stdin.readline
N = int(input().strip())
blue = {}
for _ in range(N):
s = input().strip()
blue[s] = blue.get(s,0)+1
M = int(input().strip())
red = {}
for _ in range(M):
t = input().strip()
red[t] = red.get(t,0)+1
max_net = 0
for key in set(blue.keys()) | set(red.keys()):
net = blue.get(key,0) - red.get(key,0)
if net > max_net:
max_net = net
print(max_net)
But we must ensure we consider strings not in union: net=0 already.
Example3: max net = -9 -> max_net = 0 (since initial 0 and negative not larger). prints 0.
Example4: Blue: red:3, blue:1, yellow:2. Red: red:2, yellow:1, green:1, blue:1? Actually red list: red, red, yellow, green, blue => red:2, yellow:1, green:1, blue:1. Net: red:3-2=1; blue:1-1=0; yellow:2-1=1; green:0-1=-1; others? answer max net = 1, correct.
Thus solution done.
But wait: The problem says "At most how much can he earn on balance?" It might be interpreted as maximum net gain. Since he can choose the string. So yes.
Thus final answer.
But hold on: Could there be a scenario where the best net is positive but less than 0? No.
Thus implement.
Now, we need to provide final answer in the required output format.
All set. ```python
import sys
def solve() -> None:
input = sys.stdin.readline
code
N = int(input())
blue = {}
for _ in range(N):
s = input().strip()
blue[s] = blue.get(s, 0) + 1
M = int(input())
red = {}
for _ in range(M):
t = input().strip()
red[t] = red.get(t, 0) + 1
ans = 0
# Consider all strings that appear on at least one card
for key in set(blue.keys()) | set(red.keys()):
net = blue.get(key, 0) - red.get(key, 0)
if net > ans:
ans = net
# Strings that appear nowhere give net 0, already covered by ans=0
print(ans)