Problem:
 Score : 200 points    Problem Statement 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 .        Sample Input 1 3
apple
orange
apple
1
grape      Sample Output 1 2  He can earn 2 yen by announcing apple .       Sample Input 2 3
apple
orange
apple
5
apple
apple
apple
apple
apple      Sample Output 2 1  If he announces apple , he will lose 3 yen. If he announces orange , he can earn 1 yen.       Sample Input 3 1
voldemort
10
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort      Sample Output 3 0  If he announces voldemort , he will lose 9 yen. If he announces orange , for example, he can avoid losing a yen.       Sample Input 4 6
red
red
blue
yellow
yellow
red
5
red
red
yellow
green
blue      Sample Output 4 1

Solution (Python):
import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)

CARDS = defaultdict(int)
N = int(input())

for _ in range(N):
    s = input()
    CARDS[s] += 1

M = int(input())

for _ in range(M):
    s = input()
    CARDS[s] -= 1

ans = 0
for v in CARDS.values():
    ans = max(v, ans)


print(ans)

Solution (Python):


from collections import Counter


def main():
    N = int(input())
    S = [input() for _ in range(N)]
    M = int(input())
    T = [input() for _ in range(M)]

    s = Counter(S)
    t = Counter(T)
    result = 0

    for key, value in s.items():
        if value - t[key] > result:
            result = value - t[key]

    print(result)


if __name__ == "__main__":
    main()

Solution (Python):




def main():
    N = int(input())
    S = [input() for _ in range(N)]
    M = int(input())
    T = [input() for _ in range(M)]
    result = {}
    for s in S:
        if s in result.keys():
            result[s] += 1
        else:
            result[s] = 1
    for t in T:
        if t in result.keys():
            result[t] -= 1
        else:
            result[t] = -1

    print(max(max(result.values()), 0))


if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict
bjisho = defaultdict(int)
rjisho = defaultdict(int)
blue = int(input())
for i in range(blue):
    bjisho[input()] += 1
red = int(input())
for i in range(2+blue, red+2+blue):
    rjisho[input()] += 1
for i in bjisho:
    if i in rjisho:
        bjisho[i] -= rjisho[i]
dst = max(bjisho.values()) if max(bjisho.values()) > 0 else 0
print(dst)

Solution (Python):
N = int(input())
s_lst = [input() for i in range(N)]
M = int(input())
t_lst = [input() for i in range(M)]

dict = {}
for i in s_lst:
    if not i in dict.keys():
        dict[i] = 1
    else:
        dict[i] += 1
for i in t_lst:
    if not i in dict.keys():
        dict[i] = -1
    else:
        dict[i] -= 1

infinity = float('inf')
max = -infinity
for i in dict.values():
    if max < i:
        max = i
print(max) if max > 0 else print(0)

Solution (Python):
N = int(input())
s_lst = [input() for i in range(N)]
M = int(input())
t_lst = [input() for i in range(M)]

dict = {}
for i in s_lst:
    dict[i] = 0
for i in t_lst:
    dict[i] = 0
for i in s_lst:
    dict[i] += 1
for i in t_lst:
    dict[i] -= 1
infinity = float('inf')
max = -infinity
for i in dict.values():
    if max < i:
        max = i
print(max) if max > 0 else print(0)

Solution (Python):
N = int(input())
s = []
for _ in range(N):
    s.append(input())

M = int(input())
t = []
for _ in range(M):
    t.append(input())


ans = []
for i in s:
    plus = s.count(i)
    minus = t.count(i)

    score = (plus - minus)
    ans.append(score)

if max(ans) < 0:
    print(0)
else:
    print(max(ans))

Solution (Python):
n = int(input())
l_n = [input() for i in range(n)]
m = int(input())
l_m = [input() for i in range(m)]
max_c = 0
for i in range(n):
    max_c = max(max_c, l_n.count(l_n[i]) - l_m.count(l_n[i]))
print(max_c)

Solution (Python):
import collections
n=int(input())
s=[]
for _ in range(n):
	s.append(input())
c=collections.Counter(s)
m=int(input())
for _ in range(m):
	t=input()
	c[t] -= 1
if max(c.values()) >= 0:
	print(max(c.values()))
else:
	print(0)

Solution (Python):
from collections import defaultdict

b = defaultdict(int)
r = defaultdict(int)

n = int(input())
for i in range(n):
    b[input()] += 1
m = int(input())
for i in range(m):
    r[input()] += 1
ans = 0
for k, v in b.items():
    ans = max(ans, v - r[k])
print(ans)

Solution (Python):
from collections import defaultdict
b = defaultdict(int)
r = defaultdict(int)

n = int(input())
for i in range(n):
  b[input()]+=1
m = int(input())
for i in range(m):
  r[input()]+=1
  
ans = 0
for k, v in b.items():
  ans = max(ans, v - r[k])
for k, v in r.items():
  ans = max(ans, b[k] - v)
print(ans)

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]

ans = [0]
for i in s:
    in_s = s.count(i)
    in_t = t.count(i)
    ans.append(in_s-in_t)
print(max(ans))

Solution (Python):
N = int(input())
S = [input() for __ in range(N)]
M = int(input())
T = [input() for __ in range(M)]

dic_S = {x:0 for x in set(S)}
dic_T = {x:0 for x in set(T)}
ans = list(range(len(set(S))))
for s in S:
    dic_S[s] += 1
for t in T:
    dic_T[t] += 1
for i,key in enumerate(dic_S):
    if key in list(dic_T.keys()):
        ans[i] = dic_S[key]-dic_T[key]
    else:
        ans[i] = dic_S[key]
if max(ans) > 0:
    print(max(ans))
else:
    print(0)

Solution (Python):
n = int(input())
s = [input() for x in range(n)]

m = int(input())
t = [input() for x in range(m)]

ans = 0
for i in s:
  plus = s.count(i)
  minus = t.count(i)
  temp = plus - minus

  ans = max(ans, temp)

if ans < 0:
  ans = 0

print(ans)

Solution (Python):
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

ans = 0
for ss in s:
    tmp = 0
    for tt in t:
        if ss == tt:
            tmp -= 1
    for sss in s:
        if ss == sss:
            tmp += 1
    ans = max(ans, tmp)
print(ans)

Solution (Python):
N = int(input())
S = {}
for i in range(N):
    s = input()
    if s not in S:
        S[s] = 1
        continue
    S[s] +=1
    

M = int(input())
T = {}
for i in range(M):
    t = input()
    if t not in T:
        T[t] = 1
        continue
    T[t] += 1

ans = 0
for key in S.keys():
    if key not in T:
        ans = max(ans, S[key])
        continue
    ans = max(ans, S[key] - T[key])
print(ans)

Solution (Python):
n = int(input().strip())
s = [input().strip() for _ in range(n)]
m = int(input().strip())
t = [input().strip() for _ in range(m)]
ans = 0

for i in range(n):
    tmp = s[i]
    cnt = 0
    for j in range(n):
        if s[j] == tmp:
            cnt += 1

    for j in range(m):
        if t[j] == tmp:
            cnt -= 1
    ans = max(ans, cnt)
print(ans)

Solution (Python):
n = int(input())
sl = ["" for _ in range(n)]
for i in range(n):
    sl[i] = input()

m = int(input())
tl = ["" for _ in range(m)]
for i in range(m):
    tl[i] = input()

ans = 0
for blue_word in sl:
    ans = max(ans, (sl.count(blue_word)-tl.count(blue_word)))

print(ans)

Solution (Python):
n=[input() for _ in range(int(input()))]
m=[input() for _ in range(int(input()))]
l=list(set(n))
print(max(0,max(n.count(l[i])-m.count(l[i]) for i in range(len(l)))))

Solution (Python):
n=[input() for _ in range(int(input()))]
m=[input() for _ in range(int(input()))]
l=list(set(n))
print(max(0,max(n.count(l[i])-m.count(l[i]) for i in range(len(l)))))

Solution (Python):
N=int(input())
s=[input() for _ in range(N)]
M=int(input())
t=[input() for _ in range(M)]
def ans1(x):
    return s.count(x)-t.count(x)
ans2=0
ans_1=0
for S in s:
    if ans1(S)>0 and ans1(S)>ans2:
            ans2=ans1(S)
if ans2>=0:
    print(ans2)
else:
    print("0")

Solution (Python):
ans = {}
n = int(input())
for _ in range(n):
    s = input()
    ans.setdefault(s, 0)
    ans[s] += 1

m = int(input())
for _ in range(m):
    t = input()
    ans.setdefault(t, 0)
    ans[t] -= 1

ans = sorted(ans.items(), key=lambda x: x[1], reverse=True)
print(max(0, ans[0][1]))

Solution (Python):
n=int(input())
slist=[input() for i in range(n)]
m=int(input())
tlist=[input() for i in range(m)]
words = set(slist) | set(tlist)
ans=0
for i in words:
  l = slist.count(i) - tlist.count(i)
  ans = max(l,ans)
print(ans)

Solution (Python):
d={0:0}
for i in (1,-1):
  for _ in [0]*int(input()):s=input();d[s]=d.get(s,0)+i
print(max(d.values()))

Solution (Python):
d = {'':0}
for i in (1,-1):
  for _ in range(int(input())):
    s = input()
    d[s] = d.get(s,0)+i
print(max(d.values()))

Solution (Python):
n = int(input())
d = {'':0}
for _ in range(n):
  s = input()
  d[s] = d.get(s,0)+1
m = int(input())
for _ in range(m):
  t = input()
  d[t] = d.get(t,0)-1
print(max(d.values()))

Solution (Python):
n = int(input())
d = {}
for _ in range(n):
  s = input()
  if s in d:
    d[s] += 1
  else:
    d[s] = 1
m = int(input())
for _ in range(m):
  t = input()
  if t in d and d[s] > 0:
    d[t] -= 1
print(max(d[s] for s in d))

Solution (Python):
from collections import defaultdict
d = defaultdict(int)

n = int(input())
for _ in range(n):
    d[input()] += 1
m = int(input())
for _ in range(m):
    d[input()] -= 1
print(max(0, max(d.values())))

Solution (Python):
import collections
n=int(input())
a=collections.Counter([str(input()) for _ in range(n)])
m=int(input())
b=collections.Counter([str(input()) for _ in range(m)])
ans=0
for k,v in a.items():
  if b.get(k) is None:
    ans=max(ans,v)
  else:
    ans=max(ans,v-b.get(k))
print(ans)

Solution (Python):
n = input()
red = []
for i in range(n):
    red.append(raw_input())
k = input()
blue = []
for j in range(k):
    blue.append(raw_input())
ans = 0
for r in red:
    counterR = 0
    counterB = 0
    for word in red:
        if word == r:
            counterR += 1
    for word in blue:
        if word == r:
            counterB += 1
    if ans < counterR - counterB:
        ans = counterR - counterB
print ans

Solution (Python):
n = input()
red = []
for i in range(n):
    red.append(raw_input())
k = input()
blue = []
for j in range(k):
    blue.append(raw_input())
ans = 0
for r in red:
    counterR = 0
    counterB = 0
    for word in red:
        if word == r:
            counterR += 1
    for word in blue:
        if word == r:
            counterB += 1
    if ans < counterR - counterB:
        ans = counterR - counterB
print ans

Solution (Python):
from collections import defaultdict

n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

ds = defaultdict(int)
dt = defaultdict(int)

for e in s:
    ds[e] += 1

for e in t:
    dt[e] += 1

ans = 0
for k, v in ds.items():
    money = v - dt[k]
    ans = max(ans, money)

print(ans)

Solution (Python):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    get=[]
    ct=0
    for i in range(n):
        get.append(STR())
    m=INT()
    lost=[]
    for i in range(m):
        lost.append(STR())
    get_set=set(get)
    for gs in get_set:
        temp=get.count(gs)-lost.count(gs)
        ct=max(ct,temp)
    print(ct)
        
if __name__ == '__main__':
    do()

Solution (Python):
n = int(input())
s = ['.'] * n
for i in range(n):
    s[i] = str(input())

m = int(input())
t = ['.'] * m
for i in range(m):
    t[i] = str(input())

ans = 0
for i1 in range(n):
    score = 0
    for i2 in range(n):
        if s[i1] == s[i2]:
            score += 1
    for j in range(m):
            if s[i1] == t[j]:
                score -= 1
    if ans <= score:
        ans = score

print(ans)

Solution (Python):
import math
import sys
import numpy as np
import collections




n = int(input())
s = [""]*n
for i in range(n):
  s[i] = str(input())
m = int(input())
t = [""]*m
for i in range(m):
  t[i] = str(input())


c1 = collections.Counter(s)
c2 = collections.Counter(t)
score = [0]*len(s)
counter = 0

for i in c1.keys():
  score[counter] = c1[i] - c2[i]
  counter = counter + 1

if(max(score) >= 0):
  print(max(score))
else:
  print(0)

Solution (Python):
N = int(input())
s = []
ans = 0
x = dict()
for i in range(N):
    s.append(input())
    if s[i] in x:
        x[s[i]] += 1
    else:
        x[s[i]] = 1
M = int(input())
t = []
for i in range(M):
    t.append(input())
    if t[i] in x:
        x[t[i]] -= 1

for idx in x:
    ans = max(ans,x[idx])
print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]

st = set(s) | set(t)

d1 = defaultdict(int)
d2 = defaultdict(int)

for key in s:
    d1[key] += 1
for key in t:
    d2[key] -= 1

answer = 0
for key in st:
    answer = max(answer, d1[key]+d2[key])
print(answer)

Solution (Python):
n = int(input())
s = list(input() for _ in range(n))
m = int(input())
t = list(input() for _ in range(m))
ans = 0

for i in range(n):
    if(s.count(s[i])-t.count(s[i]) > ans):
        ans = s.count(s[i])-t.count(s[i])
print(ans)

Solution (Python):
nn=int(input())
s_list=[]
for i in range(nn):
	s_list.append(str(input()))
mm=int(input())
t_list=[]
for j in range(mm):
	t_list.append(str(input()))

count_list=[]
for k in range(nn):
	name = s_list[k]
	count=0
	for l in range(nn):
		if name==s_list[l]:
			count+=1
	for m in range(mm):
		if name==t_list[m]:
			count-=1
	count_list.append(count)

max_value=max(count_list)
if max_value<=0:
	max_value=0
print(max_value)

Solution (Python):
import sys

nn=int(input())
s_list=[]
for i in range(nn):
	s_list.append(str(input()))
mm=int(input())
t_list=[]
for j in range(mm):
	t_list.append(str(input()))

count_list=[]
for k in range(nn):
	name = s_list[k]
	count=0
	for l in range(nn):
		if name==s_list[l]:
			count+=1
	for m in range(mm):
		if name==t_list[m]:
			count-=1
	count_list.append(count)

for n in range(mm):
	name = t_list[n]
	count=0
	for o in range(nn):
		if name==s_list[o]:
			count+=1
	for p in range(mm):
		if name==t_list[p]:
			count-=1
	count_list.append(count)
max_value=max(count_list)
if max_value<=0:
	max_value=0
print(max_value)

Solution (Python):
n = int(input())
s = {}
for i in range(n):
    a = input()
    if a in s:
        s[a] += 1
    else:
        s[a] = 1
t = {}
m = int(input())
for i in range(m):
    a = input()
    if a in t:
        t[a] += 1
    else:
        t[a] = 1
ans = 0
for i,j in s.items():
    if i in t:
        if j > t[i]:
            ans = max(ans,j-t[i])
    else:
        ans = max(ans,j)
print(ans)

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
dics = {}
for i in s:
	if i in dics:
		dics[i] += 1
	else:
		dics[i] = 1
dict = {}
for j in t:
	if j in dict:
		dict[j] += 1
	else:
		dict[j] = 1
ans = 0
for i in dics.keys():
	if i in dict:
		ans = max(ans, dics[i]-dict[i])
	else:
		ans = max(ans, dics[i])
print (ans)

Solution (Python):
n = int(input())
score = {}
for _ in range(n):
    blue = input()
    if blue in score:
        score[blue] += 1
    else:
        score[blue] = 1
m = int(input())
for _ in range(m):
    red = input()
    if red in score:
        score[red] -= 1
    else:
        score[red] = -1
dict_max = max(score.values())
print(max(dict_max,0))

Solution (Python):
from collections import Counter
N = int(input())
s = Counter([input() for _ in range(N)])

M = int(input())
t = Counter([input() for _ in range(M)])

point = [get - t[word] for word, get in s.items()]
print(max(max(point), 0))

Solution (Python):

from collections import defaultdict

n = int(input())
sd = defaultdict(int)
for _ in range(n):
    s = input()
    sd[s] += 1

m = int(input())
td = defaultdict(int)
for _ in range(m):
    t = input()
    td[t] += 1

res = 0
for s in sd:
    res = max(res, sd[s] - td[s])
print(res)

Solution (Python):
from collections import Counter
N=int(input())
s=[input() for _ in range(N)]
M=int(input())
t=[input() for _ in range(M)]

s1=Counter(s)
t1=Counter(t)

s1.subtract(t1)
if (s1.most_common()[0][1]<0):
    print("0")
else:
    print(s1.most_common()[0][1])

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
ans = 0
for i in range(n):
    ans1 = 0
    for j in range(n):
        if s[i] == s[j]:
            ans1 += 1
    for k in range(m):
        if s[i] == t[k]:
            ans1 -= 1
    ans = max(ans, ans1)
print(ans)

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
l = [0]*100
for i in range(n):
    ans = 0
    for j in range(n):
        if s[i] == s[j]:
            ans += 1
    for k in range(m):
        if s[i] == t[k]:
            ans -= 1
    l[i] = ans
print(max(max(l), 0))

Solution (Python):
n = int(input())
N = ['']*n
for i in range(n):
    N[i] = input()
m = int(input())
M = ['']*m
for i in range(m):
    M[i] = input()
r = 0
for i in N:
    r = max(N.count(i)-M.count(i), r)
print(r)

Solution (Python):
N = int(input())
n = []
for i in range(N):
    n.append(input())
M = int(input())
m = []
for i in range(M):
    m.append(input())
ma = 0
for i in n:
    ma = max((n.count(i)-m.count(i)),ma)
print(ma)

Solution (Python):
n = [input() for _ in range(int(input()))]
m = [input() for _ in range(int(input()))]
l = list(set(n))
print(max(0,max(n.count(l[i])-m.count(l[i]) for i in range(len(l)))))

Solution (Python):
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

res = 0
for i in set(s):
  res = max(s.count(i) - t.count(i), res)

print(res)

Solution (Python):
N = int(input())
n=[]
for i in range(N):
    n.append(input())
M = int(input())
m=[]
for i in range(M):
    m.append(input())
ma=0
for i in n:
    ma=max((n.count(i)-m.count(i)), ma)
print(ma)

Solution (Python):

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(input())
a = [input() for _ in range(n)]
m = int(input())
b = [input() for _ in range(m)]
c = list(set(a))
ans = 0
for i in c:
    if a.count(i) > b.count(i): ans = max(ans,a.count(i) - b.count(i))
print(ans)

Solution (Python):




n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

lst = list(set(s))
ans = 0
for i in range(len(lst)):
    a = lst[i]
    b = s.count(a) - t.count(a)
    if b > ans:
        ans = b
        
print(ans)

Solution (Python):
from collections import defaultdict

def solve(n, S, m, T):
    d = defaultdict(int)
    for s in S:
        d[s] += 1
    for t in T:
        d[t] -= 1
    return max(0, max(d.values()))

_n = int(input())
_S = [input() for _ in range(_n)]
_m = int(input())
_T = [input() for _ in range(_m)]
print(solve(_n, _S, _m, _T))

Solution (Python):
n = int(input())
ss = [0] * n
for i in range(n):
    ss[i] = input()

m = int(input())
ts = [0]*m
for i in range(m):
    ts[i] = input()

ans = 0
t = 0

for i in range(n):
    t = 0
    for j in range(n):
        if ss[i] == ss[j]:
            t += 1
    for k in range(m):
        if ss[i] == ts[k]:
            t -= 1
    ans = max(ans,t)

print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
dic = defaultdict(int)
for i in range(N):
    s = input()
    dic[s] += 1
M = int(input())
for i in range(M):
    t = input()
    dic[t] -= 1
ans = max(dic.values())
print(max(0,ans))

Solution (Python):
from collections import Counter

N = int(input())
sc = Counter([input() for _ in range(N)])

M = int(input())
tc = Counter([input() for _ in range(M)])
ans = 0
for s in sc.most_common():
    k, v = s
    ans = max(ans, v - tc[k])
print(ans)

Solution (Python):
from collections import Counter

N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]

C_S = Counter(S)
C_T = Counter(T)
C_S.subtract(C_T)
print(max(0, C_S.most_common(1)[0][1]))

Solution (Python):
from collections import Counter, defaultdict


def solve():
    N = int(input())
    
    A = [input() for _ in range(N)]
    count_A = Counter(A)
    
    M = int(input())
    B = [input() for _ in range(M)]
    count_B = Counter(B)
    for k,v in count_B.items():
        if k in count_A:
            count_A[k] -= v
    
    ret = count_A.most_common()[0][1]
    print(max(ret,0))
    
solve()

Solution (Python):
from collections import Counter

N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]

S_cnt = Counter(S)
S_key = S_cnt.keys()
T_cnt = Counter(T)

for key,v in T_cnt.items():
    if not key in S_key:
        continue
    S_cnt[key] -= v
print(max(max(S_cnt.values()), 0))

Solution (Python):
import collections


N = int(input())
s = []

for _ in range(N):
    s.append(input())

M = int(input())
t = []

for _ in range(M):
    t.append(input())
    
c = collections.Counter(s).most_common()
d = collections.Counter(t).most_common()


m = 0
for e in c:
    g = e[1]
    for f in d:
        if e[0] == f[0]:
            g -= f[1]
    if g > m:
        m = g
print(m)

Solution (Python):
N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]
S_Set = set(S)
ans = 0

for s in S_Set:
    ans = max(ans, S.count(s) - T.count(s))

print(ans)

Solution (Python):
List1 = [input() for i in range(int(input()))]
List2 = [input() for i in range(int(input()))]

Set1 = set(List1)

print(max(max([List1.count(item) - List2.count(item) for item in Set1]),0))

Solution (Python):
dic = {"": 0}

n = int(input())
for i in range(n):
  inp = input()
  if inp in dic:
    dic[inp] += 1
  else:
    dic[inp] = 1

m = int(input())
for i in range(m):
  inp = input()
  if inp in dic:
    dic[inp] -= 1
  else:
    dic[inp] = -1

print(max(dic.values()))

Solution (Python):
n=int(input())
b=[input() for _ in range(n)]
m=int(input())
r=[input() for _ in range(m)]
d={}
for i in range(n):
  if b[i] in d:
    d[b[i]]+=1
  else:
    d[b[i]]=1
for i in range(m):
  if r[i] in d:
    d[r[i]]-=1
  else:
    d[r[i]]=-1
ans=max(d.values())
if ans<0:
  print(0)
else:
  print(ans)

Solution (Python):
n=int(input())
s=[input() for i in range(n)] 
m=int(input())
t=[input() for i in range(m)] 
a=0
for i in set(s):
    a=max(s.count(i)-t.count(i),a)
print(a)

Solution (Python):
import collections
n = int(input())
li1 = list(input() for _ in range(n))
li1 = collections.Counter(li1)

m = int(input())
li2 = list((input() for _ in range(m)))
li2 = collections.Counter(li2)

li3 = li1 - li2


if li3 == collections.Counter():
    print(0)
else:
    print(max(li3.values()))

Solution (Python):
from itertools import groupby as gb 
n=int(input())
sl,vl=[list(a) for a in zip(*[(s,len(list(i))) for s,i in gb(sorted([input() for i in range(n)]))])]
m=int(input())
slm,vlm=[list(a) for a in zip(*[(s,-len(list(i))) for s,i in gb(sorted([input() for i in range(m)]))])]
for i in set(sl)&set(slm):
  vl[sl.index(i)]+=vlm[slm.index(i)]
print(max(0,max(vl)))

Solution (Python):
def solve():
  from itertools import groupby as gb 
  n=int(input())
  sl,vl=[list(a) for a in zip(*[(s,len(list(i))) for s,i in gb(sorted([input() for i in range(n)]))])]
  m=int(input())
  slm,vlm=[list(a) for a in zip(*[(s,-len(list(i))) for s,i in gb(sorted([input() for i in range(m)]))])]
  for i in set(sl)&set(slm):
    vl[sl.index(i)]+=vlm[slm.index(i)]
  print(max(0,max(vl)))
  
if __name__=="__main__":
  solve()

Solution (Python):
def solve():
  from itertools import groupby as gb 
  n=int(input())
  l=[(s,len(list(i))) for s,i in gb(sorted([input() for i in range(n)]))]
  sl,vl=[list(a) for a in zip(*l)]
  m=int(input())
  lm=[(s,-len(list(i))) for s,i in gb(sorted([input() for i in range(m)]))]
  slm,vlm=[list(a) for a in zip(*lm)]
  for i in set(sl)&set(slm):
    vl[sl.index(i)]+=vlm[slm.index(i)]
  print(max(0,max(vl)))
  
if __name__=="__main__":
  solve()

Solution (Python):
from itertools import groupby as gb 
n=int(input())
l=[(s,len(list(i))) for s,i in gb(sorted([input() for i in range(n)]))]
sl,vl=[list(a) for a in zip(*l)]
m=int(input())
lm=[(s,-len(list(i))) for s,i in gb(sorted([input() for i in range(m)]))]
slm,vlm=[list(a) for a in zip(*lm)]
for i in set(sl)&set(slm):
  vl[sl.index(i)]+=vlm[slm.index(i)]
print(max(0,max(vl)))

Solution (Python):
from itertools import groupby as gb 
n=int(input())
l=[(s,len(list(i))) for s,i in gb(sorted([input() for i in range(n)]))]
sl,vl=[list(a) for a in zip(*l)]
m=int(input())
lm=[(s,-len(list(i))) for s,i in gb(sorted([input() for i in range(m)]))]
slm,vlm=[list(a) for a in zip(*lm)]
for i in set(sl)&set(slm):
  vl[sl.index(i)]+=vlm[slm.index(i)]
print(max(0,max(vl)))

Solution (Python):
s=[]
t=[]

n=int(input())
for i in range(n):
    s.append(input())
m=int(input())
for i in range(m):
    t.append(input())

word=set(s)

max_point = -101


for w in word:
    tmp=s.count(w)-t.count(w)
    if tmp >= max_point:
        max_point = tmp

if max_point < 0:
    print(0)
else:
    print(max_point)

Solution (Python):
N = int(input())
cards = {"a" * 10: 0}
for _ in range(N):
    s = input()
    cards[s] = cards.get(s, 0) + 1
M = int(input())
for _ in range(M):
    s = input()
    cards[s] = cards.get(s, 0) - 1
print(max(cards.values()))

Solution (Python):
from collections import Counter

n = int(input())
lst1 = [input() for i in range(n)]
m = int(input())
lst2 = [input() for i in range(m)]



l = Counter(lst1)
k = Counter(lst2)

ans = 0

for i in l:
    if i in lst2:
        ans = max(ans,l[i]-k[i])
    else:
        ans = max(ans,l[i])

print(ans)

Solution (Python):
N = int(input())

card = {}

for i in range(N):
    s = input()
    if s in card:
        card[s] += 1
    else:
        card[s] = 1

M = int(input())
for i in range(M):
    t = input()
    if t in card:
        card[t] -= 1
    else:
        card[t] = -1

print(max(max(card.values()), 0))

Solution (Python):
from collections import defaultdict


count = defaultdict(int)
n = int(input())
for _ in range(n):
    s = input()
    count[s] += 1

m = int(input())
for _ in range(m):
    s = input()
    count[s] -= 1

ans = [num for num in count.values()] + [0]
print(max(ans))

Solution (Python):
n = int(input())
r = [input() for _ in range(n)]
m = int(input())
b = [input() for _ in range(m)]

set_r = list(set(r))

ans = 0
for i in set_r:
	ans = max(ans, r.count(i) - b.count(i))
print(ans)

Solution (Python):
from collections import Counter
S = Counter([input() for _ in range(int(input()))])
T = Counter([input() for _ in range(int(input()))])
print(max(0, max(v-(T[k] if k in T else 0) for k, v in S.items())))

Solution (Python):
n = int(input())
plus = []
for i in range(n):
  plus.append(input())

m = int(input())
minus = []
for i in range(m):
  minus.append(input())

uniq = set(plus+minus)

result = []
for i in uniq:
  result.append(plus.count(i)-minus.count(i))

if max(result) < 0:
  print(0)
else:
  print(max(result))

Solution (Python):
N = int(input())
s = [input() for _ in range(N)]

M = int(input())
t = [input() for _ in range(M)]

ans = [s.count(si) - t.count(si) for si in set(s)]

print(max(0, max(ans)))

Solution (Python):
N = int(input())
blue = [input() for _ in range(N)]
M = int(input())
red = [input() for _ in range(M)]

cards = set(blue) | set(red)
blue_map = {}
red_map = {}
for x in blue:
    if blue_map.get(x) is None:
        blue_map[x] = 1
    else:
        blue_map[x] += 1

for x in red:
    if red_map.get(x) is None:
        red_map[x] = 1
    else:
        red_map[x] += 1

result = max([blue_map.get(key, 0) - red_map.get(key, 0) for key in cards])
if result < 0:
    result = 0
print(result)

Solution (Python):

N = int(input())
s = [''] * N
for i in range(N):
    s[i] = str(input())


M = int(input())
t = [''] * M
for i in range(M):
    t[i] = str(input())


scoreList1 = []
for i in range(N):
    win1 = 0
    lose1 = 0
    if s[i] in s:
        win1 += s.count(s[i])
    if s[i] in t:
        lose1 += t.count(s[i])
    if s.count(s[i]) < t.count(s[i]):
        win1 = 0
        lose1 = 0
    scoreList1.append(win1 - lose1)

scoreList2 = []
for j in range(M):
    win2 = 0
    lose2 = 0
    if t[j] in s:
        win2 += s.count(t[j])
    if t[j] in t:
        lose2 += t.count(t[j])
    if s.count(t[j]) < t.count(t[j]):
        win2 = 0
        lose2 = 0
    scoreList2.append(win2 - lose2)

scoreList = scoreList1 + scoreList2
print(max(scoreList))

Solution (Python):
N = int(input())

blue_dict = {}
red_dict = {}

for i in range(N):
  tmp = input()
  if tmp in blue_dict:
    blue_dict[tmp] += 1
  else:
    blue_dict[tmp] = 1
    
M = int(input())
for i in range(M):
  tmp = input()
  if tmp in red_dict:
    red_dict[tmp] += 1
  else:
    red_dict[tmp] = 1


blue_dict = sorted(blue_dict.items(), key = lambda x: x[1])
red_dict = sorted(red_dict.items(), key = lambda x: x[1])


def search_red(red_dict, word):
  for i in red_dict:
    if i[0] == word:
      return i[1]
  return 0

ans = 0
for i in blue_dict:
    ans = max(ans, i[1] - search_red(red_dict, i[0]))

print(ans)

Solution (Python):
x=[]

n=int(input())
d1={}
for i in range(n):
  s=input()
  x.append(s)
  if s in d1:
    d1[s]+=1
  else:
    d1[s]=1
    
m=int(input())
d2={}
for i in range(m):
  t=input()
  x.append(t)
  if t in d2:
    d2[t]+=1
  else:
    d2[t]=1

ans=0
for s in x:
  cnt=0
  if s in d1:
    cnt+=d1[s]
  if s in d2:
    cnt-=d2[s]
  if ans<cnt:
    ans=cnt

print(ans)

Solution (Python):
import sys
N = int(input())
A=[input() for i in range(N)]
M = int(input())
B=[input() for i in range(M)]
s = list(set(A) | set(B))
cnt = 0
for i in s:
  cnt = max(cnt,A.count(i)-B.count(i))

print(max(0,cnt))

Solution (Python):
from collections import defaultdict
N = int(input())
s_cards = [input() for _ in range(N)]
M = int(input())
t_cards = [input() for _ in range(M)]

d = defaultdict(int)
for s in s_cards:
    d[s] += 1

m = 0
for s in d:
    m = max(m, d[s] - t_cards.count(s))
print(m)

Solution (Python):
a = [input() for _ in range(int(input()))]
b = [input() for _ in range(int(input()))]
c = a + b
print(max(0, max([ a.count(i) - b.count(i) for i in set(c)])))

Solution (Python):
n = int(input())
s = []
for i in range(n):
   s.append(input())
m = int(input())
t = []
for i in range(m):
   t.append(input())

score = [s.count(x) - t.count(x) for x in s]
smax = max(score)
if (smax < 0):
   print(0)
else:
   print(smax)

Solution (Python):
N = int(input())

d = {}
 
for _ in range(N):
    s = input()
    if s in d:
        d[s] = d[s] + 1
    else:
        d[s] = 1

M = int(input())

for _ in range(M):
    t = input()
    if t in d:
        d[t] = d[t] - 1
    else:
        d[t] = 0

max = 0

for key in d:
    if d[key]>max:
        max = d[key]

print(max)